Solved

PHP preg question

Posted on 2014-12-31
2
119 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
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.

738 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