Jump to content

Site search page


Thin_icE

Recommended Posts

Hi, this is my first time on this forum, hope you guys can help me on my quest.

 

I need to make some changes to an existing search page on a website using php and mysql, at the moment it is working well, except for one thing: special characters (accentuated characters and so). I mean, if one inputs a search phrase with the special characters on their place (ex: olá) it will return results, while inputting the same phrase without the special characters (ex: ola) will return no results. This is due to the sql tables containing the special characters in html code format (ex: olá).

I have a function to replace every special character for the "regular" version (ex: á => a), but the thing is, I can't apply it to the sql fields while performing the query, so it's pretty much useless... I also thought about using this function to create new fields on the tables with "clean" values, but the database is too big for that.

 

Can anyone help me out on this with some fresh ideas?

Link to comment
Share on other sites

Without seeing your code it's hard to say, but I imagine you just need to call htmlentities on the string before entering it in the query....

 

$search_string = mysql_real_escape_string(htmlentities( $_POST['search_string'] ));

$sql = "SELECT * FROM table WHERE field LIKE '$search_string'";

Link to comment
Share on other sites

Thanks for your reply! I didn't post the code because I think it would be more confusing than helpful.

Anyway, about your reply: I already applied htmlentities on the user input variable, the thing is that it only works if the user matches exactly the special characters (i.e.: if the user searches for bla, it won't return blá, blà, blã, etc...). That's why I thought about stripping the user input variable of special chars, but I need to do something like that on the content of the sql tables too. This is what I'm searching for.

Link to comment
Share on other sites

The problem is this: the database is already way too big (I started working at this place recently, and this database has been in use at least for 10 years now), and all the values are stored with special characters being replaced with their html code (i.e.: á => á). Isn't there a way I can tell the database to ignore these codes while querying? I really don't know what any other options I have here rather than creating new columns to store the same values stripped of their special characters, which would be a major work...

Link to comment
Share on other sites

No, to my knowledge, ignoring them is not a possibility. I'll move the thread over to MySQL board, perhaps Fenway or one of the other MySQL gurus who don't often frequent the PHP board will have an idea.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.