替换php中字符串的值


Replace value of string in php?

我有这个字符串:

$string=<iframe width="425" height="350" frameborder="0" scrolling="no" 
marginheight="0" marginwidth="0" src="www.yourwebiste.com"></iframe>

我想把宽度从425换成248,把高度从350换成160?

我试过

str_replace('"350"', '"160"', $string);

但我运气不好

正如meustrus所提到的,首先需要在$string周围加引号。

要替换这些值,可以使用单个str_replace:

$string='<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="www.yourwebiste.com"></iframe>';
$newString = str_replace(array('425', '350'), array('248', '160'), $string);