preg_replace on customize short-code
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
精彩评论