$str =preg_replace ("/\[attach\]/is", "111", $STR); This sentence how to replace 111 to executable PHP code
$str =preg_replace ("/\[attach\]/is", "111", $STR); This sentence how to replace 111 to executable PHP code
such as $str=preg_replace ("/\[attach\]/is", "width=" 280 "/>", $str); The results come out into characters.
------Solution--------------------
This is a PHP replacement for BBCode. You should be trying to implement a kind of attachment bbcode like Discuz.
You can use Preg_replace_callback to recall callbacks.
Author:default7
<>
$str = Preg_replace_callback ("/\[attach\" (\d+) \[\/attach\]/isue ", function ($attachId = 0) {
$row = $db->query ("SELECT * from TB where id= $id")->row ();
Return ';
}, $STR);
The principle is as above, the specific code to test it yourself.
------Solution--------------------
function Get ($id) {
$value = Here is the code for the related operation
return $value;
}
$str = Preg_replace ("/\[(Attach) \]/ise", "Get (' $ ')", $str);
can also
function Get ($r) {
$value = Here is the code for the related operation
return $value;
}
$str = Preg_replace_callback ("/\[(Attach) \]/is", "get", $str);