Solved

PHP preg question

Posted on 2014-12-31
2
122 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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