开发者

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
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜