English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm trying to use "regular expressions" in my search field on my site. My search field searches an SQL database and I keep hearing about regular expressions. I'm really inexperienced when it comes to php. I've tried reading articles on reg-expressions, but they seem like they are explaining everything to advanced programmers. If anyone could please share an example on how to implement regular expressions to a search form, I'd GREATLY appreciate it. Like I mentioned before, my coding lingo is VERY minimal, so I ask that you please answer in english. lol. Thanks in advance.

P.S. I'm trying to make it to where they CAN enter special characters, but it doesn't do anything to the SQL statement. It just searches for the special characters (if at all possible).

2006-10-05 07:59:54 · 1 answers · asked by detroitkid17 2 in Computers & Internet Programming & Design

1 answers

Regular expressions, is usally known as "RegEx" which are a set of key combinations that are meant to allow people to have a large variety of control over what they are searching for.

For example, if you want a user to input a specific text in the format your looking for, then you need to make a regex pattern inorder to match what he is inputing.

The best website which I think would help you would be this:
http://www.regular-expressions.info/

And concerning your question, if you WANT to input special characters, you will just need to ESCAPE it then UNESCAPE it.
There is a special function called html_special_chars(), thats the only function you need to ensure special characters are entered, now inorder to protect your database, you would need to escape special characters in a string for use in a SQL statement. The mysql_real_escape_string() method will deal with that.

Those are built in PHP functions which will be able to help you do what you currently want. REGEX is for custom pattern matching that you want to do, take a look at the link i mentioned above for a nice simple tutorial. If you look at the weblinks below, they have some very nice examples for you to look at.

Good Luck

2006-10-05 15:07:18 · answer #1 · answered by ? 6 · 0 0

fedest.com, questions and answers