Re: [PHP] Replacing special characters with their HTML equivalents

2008-12-22 Thread Per Jessen
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. 

Your mysql table will have a characterset attribute - if what you're
inserting doesn't match, it will complain.  If converting with
htmlentities() works for your purpose, that's one solution, otherwise
I'd make the mysql table use UTF8 and then look into iconv to convert
all scraped pages to UTF8.


/Per Jessen, Zürich


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Replacing special characters with their HTML equivalents

2008-12-21 Thread Larry Garfield
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
la...@garfieldtech.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Replacing special characters with their HTML equivalents

2008-12-21 Thread James Colannino
Daniel Brown wrote:

> Welcome to the list, James.

Thanks :)

> Check out htmlentities(): http://php.net/htmlentities

I'll check that out.

James
-- 
"Black holes are where God divided by zero." --Steven Wright



signature.asc
Description: OpenPGP digital signature


[PHP] Replacing special characters with their HTML equivalents

2008-12-21 Thread James Colannino
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
-- 
"Black holes are where God divided by zero." --Steven Wright



signature.asc
Description: OpenPGP digital signature


Re: [PHP] Replacing special characters with their HTML equivalents

2008-12-21 Thread Daniel Brown
On Sun, Dec 21, 2008 at 18:30, 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.)

Welcome to the list, James.

Check out htmlentities(): http://php.net/htmlentities

-- 

daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Unadvertised dedicated server deals, too low to print - email me to find out!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php