pnm123 pnm123 - 15 days ago 5
MySQL Question

PHP escape $ sign and echo a string my fetching database

I want to know how to echo a string that have a $ sign from a database. At this time, the value on database 'Buy one for $5.00' converts to 'Buy one for .00'.

Let's say the name of the field is

and the value is
Buy one for $5.00


$body_tpl = file_get_contents('tpl.html'); //Title is: %title% blah blah %title%

$row = mysql_fetch_array(mysql_query("SELECT title FROM table WHERE id=1"));
$title = $row['title'];
$pat[] = '/%title%/sx';
$rep[] = $title;
$body = preg_replace($pat,$rep,$body_tpl);




You should use str_replace for that.

$row = mysql_fetch_array.....
$title = $row['title'];
$body = str_replace( "%title%", $title, $body_tpl );
echo $body;

Note that you can replace multiple keywords at the same time with str_replace too (see PHP docs).