View Full Version : Converting Certain Characters at run time

09-19-2005, 09:35 PM
I am loading text into the a text area at run time from a databse text field. What I wanted to know if there was anyway to convert certain characters into html (ie. For some reason everywhere in my text field every time there is supposed to be a bullet symbol the character is written and I want to convert that to the html tag for a bullet symbol). If anyone has any ideas I would most certainly appreciate it. Thanks.

09-20-2005, 08:38 AM
What scripting language are you using

09-22-2005, 03:33 AM
I am using PHP and mySQL

09-22-2005, 08:51 AM
I have used preg_replace to do this

$string = ' convert this symbol to html convert this symbol to html convert this symbol to html.';

$patterns[0] = '//';

$replacements[0] = '<li>';

echo preg_replace($patterns, $replacements, $string);

will output as...

[bullet] convert this symbol to html
[bullet] convert this symbol to html
[bullet] convert this symbol to html

as $patterns[0] and $replacements[0] are defind as an array you can look for others using $patterns[1], $patterns[2] etc and $replacements[1], $replacements[2]etc

eg ...

$patterns[3] = '/@/'; would be replaced by $replacements[3] ='&';

09-26-2005, 04:45 PM
pefect, thanks so much.

09-26-2005, 05:02 PM
-or- maybe a simpler solution: make sure you're using utf-8 for characterset. I think DW still is setup to use iso-8859-1 by default.

09-26-2005, 07:18 PM
how do I change to utf-8 for characterset?

09-26-2005, 08:41 PM
Change your existing meta tag that specifies characterset with:
<meta http-equiv="content-type" content="text/html;charset=utf-8">

09-26-2005, 10:09 PM
that changed all the to "?"....

09-27-2005, 12:57 AM
It's probably because they were not inserted into DB as utf-8 :).
If you have no control over how DB get's populated, stick to the original solution that seemed to work for you :)

09-27-2005, 02:00 AM
great, thanks for the idea anyway.