Skip to content

Tag: regex

PHP regular expression

What is purpose of the following code? What kind of $string match this expression? Why there is a character @? Answer That regular expression will match any <script>…</style> or <style>…</style> (X)HTML blocks in the string and remove them. This is most likely done to preve…

Altering .htaccess with PHP – removing a rewrite rule

I am using PHP to remove/add static pages once a page has been deleted, I want to be able to remove it from the .htaccess, however I’ve tried this, but it throws an error: Warning: preg_replace() [function.preg-replace]: Unknown modifier ” in … The code: This is an example of what it should …

Japanese/chinese email addresses?

I’m making some site which must be fully unicode. Database etc are working, i only have some small logic error. Im testing my register form with ajax if fields are valid, in email field i check with regular expressions. However if a user has a email address like 日本人@日人日本人.com it isn’t coming troug…

php regex number and + sign only

I need a php function to validate a string so it only can contains number and plus (+) sign at the front. Example: +632444747 will return true 632444747 will return true 632444747+ will return false …

Remove style attribute from HTML tags

I’m not too good with regular expressions, but with PHP I’m wanting to remove the style attribute from HTML tags in a string that’s coming back from TinyMCE. So change <p style=”…”>Text</p> to just vanilla <p>Test</p>. How would I achieve this with s…

PHP regular expression – filter number only

I know this might sound as really dummy question, but I’m trying to ensure that the provided string is of a number / decimal format to use it later on with PHP’s number_format() function. How would I do it – say someone is typing 15:00 into the text field – what regular expression and …

Stripping a string of its non-numeric characters

I have a phone number stored in $phone, it looks like this: (555) 555-5555. I want it to look like this: 5555555555. How do I take the string and strip it of hyphens, spaces, and parenthesis? Answer With a regexp. Specifically, use the preg_replace function:

Parse inline CSS values with Regex?

I have such an inline CSS like this color:#777;font-size:16px;font-weight:bold;left:214px;position:relative;top:70px The CSS may end with a semicolon “;” or not. It also can contain extra space …