开发者

preg_replace on customize short-code

开发者 https://www.devze.com 2023-04-04 11:27 出处:网络
I have the following code: {bookielink href=\"bet-at-home\"} body content{/bookielink} and I want to get the following:

I have the following code:

{bookielink href="bet-at-home"} body content{/bookielink}

and I want to get the following:

<a href="index.php?bookie=bet-at-home">body content</a>

This is my tries:

$buffer = preg_replace("/.*{bookielink[^>开发者_JAVA百科]*}|.*/si", "<a>", $buffer);
$buffer = preg_replace("/.*{\/bookielink}|.*/si", "</a>", $buffer);


The following:

$buffer = 'foo {bookielink href="bet-at-home"} body content{/bookielink} bar';
echo preg_replace(
    '#{bookielink\s+href="([^"]*)"\s*}([^{]+){/bookielink}#i', 
    '<a href="index.php?bookie=$1">$2</a>', 
    $buffer
);

will print:

foo <a href="index.php?bookie=bet-at-home"> body content</a> bar
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号