Web Hosting Talk







View Full Version : Simple PHP Problem


Tomer
08-10-2005, 07:49 PM
Look guys, I have this small problem with this PHP code, anyone know how to get it working?


$body = preg_replace("~\<code\>(.*?)\<\/code\>~is", "<div class='code'>". showsource(" .\\1. ") . "</div>", $row[body]);


Basically, I want this line to: Find all text within the code tags, and execute that function [showsource()] on the text, and place it inside the div. It's not working properly.

Best way to explain in is via example:

Before = "text1 <code>text2</code> text3";
After = "text1 <div class="code>" . showsource('text2') . "</div> text3";


Thanks

yabsoft
08-10-2005, 09:59 PM
Method1:
preg_replace_callback("expr","ParseFunc",$s);

ParseFunc is a function to process the matchment and then return a result to replace.

Method2:
preg_replace('/expr/sUe', "phpcode", $s);

The key is "/e",it will eval phpcode.

The phpcode is a vaild php script,it will be "eval()";