views:

68

answers:

1

Hello,

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 title and the value is Buy one for $5.00

<?php

$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);

print_r($body);

?>

Thank you, pnm123

+2  A: 

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).

svens
Thanks. It worked.
pnm123