Baically, i have a need to search a string for a reference, eg: [brandid:10]
then take that brand ID, 10, into a database and get its proper name.
So, blah blah blah [brandid:10] blah
becomes
blah blah blah <a href="/visit?brandten">brandten</a> blah
So far, so good with a little preg_replace:
$content = preg_replace('/\[brandid:(.*)]/', test1('$1'), $content);
Where the function is:
Code: Select all
function test1($text) {
return "<a href="/visit/$text">$text</a>";
}
So, now i need to get it from a database
Code: Select all
function test3($id) {
$sql = mysql_query ("SELECT name FROM brands WHERE id=$id");
// return value
$row = mysql_fetch_array($sql);
return "<a href="/visit/".$row[name].">".$row[name]."</a>";
}
Anyone got any thoughts as to why? Cheers muchly!!
// note: phpbb seems to remove various things from the code, i have escaped things and such