Solved

PHP preg question

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now