$ Strpreg_replace ([attach] is, 111, $ str ); how to replace 111 with executable PHP code $ str = preg_replace ("/\ [attach \]/is", "111", $ str ); how to replace 111 with executable PHP code
For example, $ str = preg_replace ("/\ [attach \]/is", "" width = "280"/> ", $ str); the result is a string
Reply to discussion (solution)
$message=preg_replace("/\[url\](http:[^\]]*?)\[\/url\]/ies","_cuturl('\\1')",$message);function _cuturl($msg){$new=cutstr($msg,20);return $new;}
After adding the symbol/e to the regular expression, you can call the function and execute the php operation.
$ Str = preg_replace ("/\ [attach \]/is", "", $ str );
This is the PHP replacement of BBCODE. You should want to implement the attachment BBCODE similar to DISCUZ.
You can use preg_replace_callback for callback.
query("select * from tb where id=$id ")->row();return '';},$str);
The principle is as follows. test the code yourself.
This is the PHP replacement of BBCODE. You should want to implement the attachment BBCODE similar to DISCUZ.
You can use preg_replace_callback for callback.
query("select * from tb where id=$id ")->row();return '';},$str);
The principle is as follows. test the code yourself.
Fixed:
$str = preg_replace_callback("/\[attach\]\s*(\d+)\s*\[\/attach\]/isUe",function($match){//todo $id = $match[1];$row = $db->query("select * from tb where id=$id ")->row();return $row ? '' : '';},$str);
$ Str = preg_replace ("/\ [attach \]/is", "", $ str)
This is the PHP replacement of BBCODE. You should want to implement the attachment BBCODE similar to DISCUZ.
You can use preg_replace_callback for callback.
query("select * from tb where id=$id ")->row();return '';},$str);
The principle is as follows. test the code yourself.
Fixed:
$str = preg_replace_callback("/\[attach\]\s*(\d+)\s*\[\/attach\]/isUe",function($match){//todo $id = $match[1];$row = $db->query("select * from tb where id=$id ")->row();return $row ? '' : '';},$str);
Error message: Parse error: syntax error, unexpected T_FUNCTION in
Point to $ str = preg_replace_callback ("/\ [attach \] \ s * (\ d +) \ s * \ [\/attach \]/isUe", function ($ match) {this line
What is your php version?
Php5.2
Function get ($ id) {// $ value = return $ value;} $ str = preg_replace ("/\ [(attach) \]/ise "," get ('$ 1') ", $ str );
Yes.
Function get ($ r) {// $ value = return $ value;} $ str = preg_replace_callback ("/\ [(attach) \]/is "," get ", $ str );
Dz's mobile phone version does not display pictures, so I want to write a display Person Page by myself.
function get($r) { $value = SELECT * FROM `bbs_forum_attachment_$row[tableid]` where tid =id return $value;}$str = preg_replace_callback("/\[(attach)\]/is", "get", $str);
Where tid = id how to get this ID
You can see it in print_r ($ r ).
You can see it in print_r ($ r ).
function get($r) { $value = "SELECT * FROM `bbs_forum_attachment_9` where tid =$r" return $value;}$str = preg_replace_callback("/\[(attach)\]/is", "get", $str);
Error message: Parse error: syntax error, unexpected T_RETURN
The semicolon at the end of the second line is missing.
The semicolon at the end of the second line is missing.
I changed it
function get($r) { $value = "SELECT * FROM `bbs_forum_attachment_9` where tid =$r"; return $value;}$str = preg_replace_callback("/\[(attach)\]/is", "get", $str);
But output the day before yesterday
SELECT * FROM 'bbs _ forum_attachment_9 'where tid = Array26588
What I want is SELECT * FROM 'bbs _ forum_attachment_9 'where tid = 26588. do not use Array.
I changed it to single quotes and output SELECT * FROM 'bbs _ forum_attachment_9 'where tid = $ r
Is this php statement not executed? it is directly converted into text
Where did 26588 come from? In the get method, what does print_r ($ r); get?
Change to $ str = preg_replace_callback ("/\ [attach \] (. + ?) \ [\/Attach \]/is "," get ", $ str); after
Output: SELECT * FROM 'bbs _ forum_attachment_9 'where tid = Array
Where did 26588 come from? In the get method, what does print_r ($ r); get?
In the get method, print_r ($ r); the value is 1.
26588 should be the first time not filtered clean
I don't understand. print_r ($ r); how can it be 1?
Php5.2
I forgot to write it. the one I wrote is PHP 5.5 +.
How can I write php5.2?