By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,649 Members | 2,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,649 IT Pros & Developers. It's quick & easy.

How to escape string for preg_match?

P: n/a
I have a string equal to 'www/' that I want to use in a preg_match. Php
keeps giving me the warning:

Warning: preg_match(): Unknown modifier '/'

How can I escape the string so the / in www/ is not interpreted in the
preg_match ?

May 10 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
tim

sq****@peoriadesignweb.com wrote:
I have a string equal to 'www/' that I want to use in a preg_match. Php
keeps giving me the warning:

Warning: preg_match(): Unknown modifier '/'

How can I escape the string so the / in www/ is not interpreted in the
preg_match ?


Either with \
preg_match( '/www\//', $str )

or use a diffrent charcter as a delimiter
preg_match( '|www/|', $str )

Tim

May 10 '06 #2

P: n/a
tim:
Either with \
preg_match( '/www\//', $str )
or preg_quote()
http://www.php.net/manual/en/function.preg-quote.php
or use a diffrent charcter as a delimiter
preg_match( '|www/|', $str )


--
Jock

May 10 '06 #3

P: n/a

tim wrote:
Either with \
preg_match( '/www\//', $str )

or use a diffrent charcter as a delimiter
preg_match( '|www/|', $str )


Actually I want to use $str in the preg_match, i.e:

preg_match( "$str" , 'www' )

but since $str is 'www/', the forward slashes causes a problem

May 10 '06 #4

P: n/a
On 2006-05-10, sq****@peoriadesignweb.com <sq****@peoriadesignweb.com> wrote:

tim wrote:
Either with \
preg_match( '/www\//', $str )

or use a diffrent charcter as a delimiter
preg_match( '|www/|', $str )


Actually I want to use $str in the preg_match, i.e:

preg_match( "$str" , 'www' )

but since $str is 'www/', the forward slashes causes a problem


As already said: they are only a problem if you use them as delimiter...
Since webdevelopment is usually about URLs (with forward slashes) i
agree that is better to use a delimiter like | instead of /.
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>
May 11 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.