Domanda

I'm trying to make a quote system, but I how to get preg_replace variables into server variables?

Don't understand?, here is the script!

$input = preg_replace("#\[quote id=(.*?)\]#si", "<blockquote><p>" . $class->functions('\\1') . "</p><p>..</p></blockquote>", $input);

the problem: The function does not know what \\1 means after $mysqli->real_escape_string() and returns \1, if I remove the real_escape_string it still says it does not exist in the database.. but it's there!!

How to fix this?

È stato utile?

Soluzione

You cannot use backreference like this. You need to use preg_replace_callback like:

function callback_function($m) {
  return "<blockquote><p>" . $class->functions($m[1]) . "</p><p>..</p></blockquote>";
}
preg_replace_callback("#\[quote id=(.*?)\]#si", "callback_function", $input);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top