469,572 Members | 1,306 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,572 developers. It's quick & easy.

How to escape string for preg_match?

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
4 14465
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
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

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
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.

Similar topics

4 posts views Thread by /dev/null | last post: by
2 posts views Thread by Ksenia Marasanova | last post: by
3 posts views Thread by qilin | last post: by
5 posts views Thread by andrei.avk | last post: by
3 posts views Thread by jmDesktop | last post: by
2 posts views Thread by ylj798 | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.