Re: Replacing special characters with their HTML equivalents

From: Date: Mon, 22 Dec 2008 00:20:24 +0000
Subject: Re: Replacing special characters with their HTML equivalents
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-284948@lists.php.net to get a copy of this message
On Sunday 21 December 2008 5:30:25 pm James Colannino wrote: > Hey everyone. I have a question. I have a web scraper that grabs > information from web pages that often contain characters such as vowels > with umlots (I know I spelled that wrong.) > > The data is editable, so the characters show up unmodified in an > editable text box. However, when I try to import the data into a MySQL > database, the first occurrence of such a character, along with the rest > of the string, is truncated from the result. Not all special characters > cause the problem; vowels with macrons work, for example. > > I don't know if it's failing during the actual query or if the character > is being filtered out at some earlier stage, but whatever the cause, > it's not working. > > My question is, is there a way to replace these characters with their > HTML equivalents? For example, the a with an umlot over the top is > ä in HTML, so before the query is made, and before the filtering on > the string is done, I'd like to replace that special character with its > HTML representation. This allows the user to see the character while > it's in its text box, yet at the same time allow it to be successfully > imported into the database. > > I know about str_replace, but assuming it's the right function for the > job, how would I go about representing these special characters in PHP > so that it will understand what I'm trying to do? > > Thanks! > > James You may find this useful: http://www.garfieldtech.com/blog/unicode-8-vs-16 -- Larry Garfield larry@garfieldtech.com

« previous php.general (#284948) next »