$str =preg_replace ("/[attach]/is" "111" $str); This sentence how to replace 111 with executable PHP code

Source: Internet
Author: User
Tags bbcode
$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);



  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.