Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 151
  • Last Modified:

PHP preg question

we've been successfully using this PHP statement as a part of an AJAX title lookup.
however, when the enduser enters a slash as a part of the title,
it gives the warning below.
how should i quote slashes or change the approach to allow slashes to be entered in the web form input field.
The function of the statement below is to add HTML tags (CSS class) to yellow-highlight
the user-input within the found-results title list items.
$search_string in this situation contains     20/

thanks!

     $HighlightedDisplayTitle = preg_replace(
                           "/(".preg_quote($search_string).")/i",
                           "<b class='Highlight'>$1</b>",
                            $Row['inventory_title'] );

Warning: preg_replace() [function.preg-replace]: Unknown modifier '1' in /public_html/ajax-title-lookup.php on line 51
0
willsherwood
Asked:
willsherwood
1 Solution
 
Terry WoodsIT GuruCommented:
Change this line:
                            "/(".preg_quote($search_string).")/i", 

Open in new window

to:
                            "/(".preg_quote($search_string, '/').")/i", 

Open in new window

so that preg_quote also escapes the delimiter (the / character, in your case).

You can see the delimiter is an optional parameter in the docs for preg_quote

Note that EE has a Regular Expressions topic area you can put against your question if you have any more regex related issues :-)
0
 
willsherwoodAuthor Commented:
EXCELLENT IN ALL ASPECTS
many thanks!!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now