PHP: automatically converting accented characters to &---;?

michaelsanford

Translator, Web Developer
http://ca.php.net/manual/en/function.htmlspecialchars.php

That function seems only to escape ' " < > &, but i'd ideally like to be able to automatically convert accented letters by their HTML entity.

Is there a function other than str_replace(); that I can use to do this?

The application: My new web site's slplash page displays a random lyrics from a MySQL database. The problem is many of them are French, so they contain accented characters. Since, strictkly speaking, there are no accented characters allowed in XHTML, I want to escape them properly for display with tags like &agrave; (which is "& agrave ;"), etc
 
I've had a similar problem.

I tried the str_replace() first, but it stretched the server a bit (old 300 MHz G3 with only 128 MB RAM).

To speed things up, I finally resorted to replacing all the special characters with html entities in the database itself instead. Not a lot of fun if you want to update it, unless you use a form page and simply do all the replacements in the form handling script. Not much performance hit unless you do a lot of updating.
 
Do you mean using an SQL query to replace the characters once they'd been submitted? I totally don't mind doing that.

At the moment, my server is running in an XServe, so I'm not worried about stretching it. ;)

Also, there will likely only be one query of this type per day, maximum (that query being an insert). I don't expect ever to edit the fields; if there is something seriously wrong with the lyrics text I'll just delete it and maybe inform the person who added it if I know them....

Do you by any chance have a nice pre-written str_replace() function, or SQL function, that will convert all the accented charcters to HTML entities that I could copy from you? :cool:

EDIT: IF you do have some PHP code, and want to post it here as opposed to email/PM, PLEASE don't put it inside the PHP tag this forum uses, when I copy/paste it, it totally messes up all the line breaks and spaces :p )
 
Back
Top