Thanks for the response, but the sql query ends up the same way in the function it places: id = $1 (not the value parsed out). I was printing it so I could see why I wasn't getting any results and passing it back in so I could see some of the mechanics. After I run it this is the page that is generated. You'll see the SQL query is echoed twice. Once in the function and once when $sql is returned.
In the function you'll see "id=$1" as the actual output and in the regular expression it appears "id=60" which means the $1 is only being parse IN the expression and is not being passed out into the function.
I also just updated the function to put a tag around the query it outputs, and what is concerning is it only outputs the data once not twice New Code:
function getimg($id)
{
$sql = "SELECT a.image_id, a.id, a.name, a.image_active, a.thumb_file, a.comments
FROM images a, categories b
WHERE a.image_active=1
AND a.id = b.id
AND a.image_id = ".$id;
echo "INFUNCTION<b>$sql</b>";
return $sql;
}
$test ="[limg=59] test of something [limg=60]";
$output_string = preg_replace( '/[limg=([0-9]+)]/i', "<a href='gallery.php?img=\1 '><img src='http://www.mythicarealms.com/gallery/".getimg('$1')."'></a>", $test );
echo $output_string;
HTML GENERATED:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
INFUNCTION<b>SELECT a.image_id, a.id, a.name, a.image_active, a.thumb_file, a.comments
FROM images a, categories b
WHERE a.image_active=1
AND a.id = b.id
AND a.image_id = $1</b><a href='gallery.php?img=59 '><img src='http://www.mythicarealms.com/gallery/SELECT a.image_id, a.id, a.name, a.image_active, a.thumb_file, a.comments
FROM images a, categories b
WHERE a.image_active=1
AND a.id = b.id
AND a.image_id = 59'></a> test of something <a href='gallery.php?img=60 '><img src='http://www.mythicarealms.com/gallery/SELECT a.image_id, a.id, a.name, a.image_active, a.thumb_file, a.comments
FROM images a, categories b
WHERE a.image_active=1
AND a.id = b.id
AND a.image_id = 60'></a>
</body>
</html>
Thanks for your reply 🙂