Solved

PHP preg question

Posted on 2014-12-31
2
117 Views
Last Modified: 2014-12-31
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
Comment
Question by:willsherwood
2 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 40526096
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
 

Author Comment

by:willsherwood
ID: 40526133
EXCELLENT IN ALL ASPECTS
many thanks!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question