PDA

View Full Version : Converting Certain Characters at run time


ltd_goods
09-19-2005, 10: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.
-jeremy

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

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

davidj
09-22-2005, 09: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] ='&';

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

domedia
09-26-2005, 06: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.

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

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

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

domedia
09-27-2005, 01: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 :)

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