我有以下代码:
{bookielink href="bet-at-home"} body content{/bookielink}
我希望得到以下内容:
<a href="index.php?bookie=bet-at-home">body content</a>
这是我的尝试:
$buffer = preg_replace("/.*{bookielink[^>]*}|.*/si", "<a>", $buffer);
$buffer = preg_replace("/.*{\/bookielink}|.*/si", "</a>", $buffer);
答案 0 :(得分:1)
以下内容:
$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
);
将打印:
foo <a href="index.php?bookie=bet-at-home"> body content</a> bar