What I thought was going to be an easy implementation of two lines of code and a function, turned out to be made of fail.
On my webpage, I want to be able to type [text]1[/text]
, and what it will do is pull the title of that ID.
function textFormat($text) {
$raw = array(
'\'\[text\](?P<id>.*?)\[/text\]\'is'
);
$out = array (
'<a href="index.php?function=getData&reference=text&id=$1">' . getTextTitle() . '</a>'
);
preg_replace($raw, $out, $text);
return $text;
}
function getTextTitle($id) {
$sql = mysql_query("SELECT title FROM text WHERE id = $id");
return mysql_result($sql);
}
So, here's the lovely little problem: As one can tell, I'm calling a function with a numeric-titled variable, which works great in the quotation marks, but as we know, PHP doesn't like that. So, I opted for a named group. Using $regs['id']
fails to work.
Am I doing something wrong?
Am I going about this the wrong way?