Re: regex/preg_replace() difficulty

From: Date: Wed, 01 Oct 2003 11:22:58 +0000
Subject: Re: regex/preg_replace() difficulty
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-164529@lists.php.net to get a copy of this message
You need to escape the period "." twice with backslashes "\\" -- Jon Kriek http://phpfreaks.com "Jonas_weber @ Gmx . Ch" <jonas_weber@gmx.ch> wrote in message news:34698BBA-F3FE-11D7-8B45-003065B32696@gmx.ch... > 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.

« previous php.general (#164529) next »