在方法调用返回的字符串上使用str_replace

时间:2012-01-19 16:40:48

标签: php string

这是客户端代码;我想在Magento字符串中包围myReplaceRR:

BEFORE

$myReplaceRRR=stripslashes($product_description);
$myReplaceRRR=str_replace("bespoke.php", "made-to-measure.php", $myReplaceRRR);
$myReplaceRRR=str_replace("***OFFER PRICE FOR A LIMITED PERIOD ONLY***", "<span style=\"color:#ed2929\">***OFFER PRICE FOR A LIMITED PERIOD ONLY***</span>", $myReplaceRRR);
echo $myReplaceRRR;

AFTER

$myReplaceRRR= $this->getChildHtml('description');
$myReplaceRRR=stripslashes($product_description);
$myReplaceRRR=str_replace("bespoke.php", "made-to-measure.php", $myReplaceRRR);
$myReplaceRRR=str_replace("***OFFER PRICE FOR A LIMITED PERIOD ONLY***", "<span style=\"color:#ed2929\">***OFFER PRICE FOR A LIMITED PERIOD ONLY***</span>", $myReplaceRRR);
echo $myReplaceRRR;

注意,我希望将其作为字符串$this->getChildHtml('description');

1 个答案:

答案 0 :(得分:2)

你应该在你的问题中尝试更具描述性。

删除第二行?

$myReplaceRRR= $this->getChildHtml('description');
$myReplaceRRR=str_replace("bespoke.php", "made-to-measure.php", $myReplaceRRR);
$myReplaceRRR=str_replace("***OFFER PRICE FOR A LIMITED PERIOD ONLY***", "<span style=\"color:#ed2929\">***OFFER PRICE FOR A LIMITED PERIOD ONLY***</span>", $myReplaceRRR);
echo $myReplaceRRR;