473,480 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 14813
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
1567
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
11658
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
6692
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
3169
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
8632
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
5273
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
1784
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
1809
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
6658
by: ylj798 | last post by:
this string from web by the Regular Expression$B!$(B $B!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!](B href="#" onClick="ConvertURL2FG('Flashget://...
0
7041
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
6929
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4779
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.