Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can addslashes be used to create REGEX pattern? 1

Status
Not open for further replies.

sen5241b

IS-IT--Management
Sep 27, 2007
199
0
0
US
I have a string, that could be any random English text, I want to insert it into a REGEX pattern. If the string were to have a comma, slash or other special character would addslashes set up the pattern for use with preg_match?
 
Hi

sen5241b]would addslashes set up the pattern for use with preg_match?
No.

You should use the dedicated [tt]preg_quote()[/tt] function :
PHP:
[COLOR=darkgoldenrod]preg_match[/color][teal]([/teal][green][i]'/'[/i][/green][teal].[/teal][COLOR=darkgoldenrod]preg_quote[/color][teal]([/teal][navy]$re[/navy][teal],[/teal][green][i]'/'[/i][/green][teal]).[/teal][green][i]'/'[/i][/green][teal],[/teal][navy]$str[/navy][teal]);[/teal]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top