[PHP] regex/preg_replace() difficulty
Regular Expressions: How can I indicate that the contents of a term (user input*) needs to be treated as 'non-operators/control characters' (as *word* to match in that exact way)? (* Because the term is a user's input I can't escape the control characters manually.) Example: $result = preg_replace('/('.$termWithOptionalBold.')(\/?span[^]*)*()/si', 'span class=highlight\1/span', $result); [If $termWithOptionalBold is a . (period) for example, any char will be matched--instead of only the .] Any suggestions? Thanks a lot for your effort! Best wishes, jonas PS: Somewhere I read that '\Q' would do something like that but it didn't work. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regex/preg_replace() difficulty
You can escape the control characters manualy ;) $termWithOptionalBold=str_replace(array('.','\','$' ),array('\.','\\','\$' ), $termWithOptionalBold); [EMAIL PROTECTED] wrote: Regular Expressions: How can I indicate that the contents of a term (user input*) needs to be treated as 'non-operators/control characters' (as *word* to match in that exact way)? (* Because the term is a user's input I can't escape the control characters manually.) Example: $result = preg_replace('/('.$termWithOptionalBold.')(\/?span[^]*)*()/si', 'span class=highlight\1/span', $result); [If $termWithOptionalBold is a . (period) for example, any char will be matched--instead of only the .] Any suggestions? Thanks a lot for your effort! Best wishes, jonas PS: Somewhere I read that '\Q' would do something like that but it didn't work. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regex/preg_replace() difficulty
From: [EMAIL PROTECTED] Regular Expressions: How can I indicate that the contents of a term (user input*) needs to be treated as 'non-operators/control characters' (as *word* to match in that exact way)? (* Because the term is a user's input I can't escape the control characters manually.) Example: $result = preg_replace('/('.$termWithOptionalBold.')(\/?span[^]*)*()/si', 'span class=highlight\1/span', $result); [If $termWithOptionalBold is a . (period) for example, any char will be matched--instead of only the .] Any suggestions? I got one! http://www.php.net/manual/en/function.preg-quote.php ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] regex (preg_replace)
Im trying to get a final output to be 'item' but Im unable to get working. Could someone point me where Im going wrong. Thanks ?php $a = 'item rdf:about=http://www.trini0.org;'; $b = preg_replace(/(item)(\s.*)()/i, $1 . $3, $a ); echo $b; ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regex (preg_replace)
I figured it out. Change the last line to echo htmlspecialchars($b); and you'll get the proper output. Gerard Samuel wrote: Im trying to get a final output to be 'item' but Im unable to get working. Could someone point me where Im going wrong. Thanks ?php $a = 'item rdf:about=http://www.trini0.org;'; $b = preg_replace(/(item)(\s.*)()/i, $1 . $3, $a ); echo $b; ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php