473,320 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 14802
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sims | last post by:
Hi, I read somewhere that there are some tricks that a hacker can use to break into the db table. But how can i test against that? Is there a function to convert all strings to 'safe' strings?...
4
by: /dev/null | last post by:
Is there a function in php that you can pass a string headed for a mysql query and have it make it 'safe'? For example it would escape out the ' found in the string. Thanks!
2
by: Ksenia Marasanova | last post by:
Hi, I have a simple ecard creation script on a website, where user can add text to a graphic. I use ImageMagick for it: # template_file => path to image template file # new_file => path to...
1
by: Harry Keck | last post by:
Is there a set of methods in the .Net framework that do the same thing as the jscript functions escape and unescape? I get very close with HttpUtility.UrlEncodeUnicode, but it puts "+" for...
3
by: qilin | last post by:
I am trying to save a big text string into MySQL, but I guess i need escape the string firstly, anybody knows any escape function in c for that? or any other suggests ?
5
by: andrei.avk | last post by:
Hi, I'd like to store chunks of text, some of them may be very large, in a database, and have them searchable using 'LIKE %something%' construct. These pieces of text may have single and double...
3
by: jmDesktop | last post by:
I have searched much but cannot find answer to this seemingly simple question. I have a function that builds an html element like this, which works fine: ...
14
by: Bennett Haselton | last post by:
I'm moving a bunch of PHP scripts from a server where they ran on PHP4, to a new server with PHP5. On the old server, variables in the query string would be automatically instantiated in the...
2
by: ylj798 | last post by:
this string from web by the Regular Expression$B!$(B $B!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!](B href="#" onClick="ConvertURL2FG('Flashget://...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.