php 字符串的 Preg 替换帮助

Preg Replace Help for php string

$testString = 'this is testing start [youtube=http://www.youtube.com/watch?v=abcd&w=640&h=390] this is last'; 

我希望将其替换为以下内容:

$testString = 'this is testing start <iframe src="http://www.youtube.com/watch?v=abcd&w=640&h=390"></iframe> this is last';

请帮忙!

您可以使用 strtr function.

试试这个:

$testString = 'this is testing start [youtube=http://www.youtube.com/watch?v=abcd&w=640&h=390] this is last'; 

$new_String = strtr($testString, array('[' => '<iframe src="', ']' => '"></iframe>'));