0

次のような文字列があります。

$post = "Test $asd$ lol test asd $test$";

私はそれがなりたい:

$post = "Test [bb]asd[/bb] lol test asd [bb]test[/bb]";

これを達成するための最も簡単で最良の方法はどれですか? $ の出現回数は時々異なることに注意してください。基本的な考え方は、他のすべてのオカレンスを [b] それぞれ [/bb] に置き換えることです。

お分かりできると良いのですが。

4

1 に答える 1

2

これを試して :

<?php
$str  = $post = 'Test $asd$ lol test asd $test$';
echo preg_replace('/\$(\w+)\$/','[bb]$1[/bb]',$str);
?>

出力:

Test [bb]asd[/bb] lol test asd [bb]test[/bb] 
于 2013-03-18T12:32:28.857 に答える