使用str_replace时出现多个数组错误

问题描述 投票:0回答:1

我想替换如下文字。

$text = '<!DOCTYPE html>
<html>
<head>
</head>
<body>
<pre><code>[[EXAMPLE]] this is a text. <br />[[EXAMPLE2]]</code></pre>
<p style="text-align: center;"><br /><br /></p>
</body>
</html>';


$products['type'] = 1;
$products['quantity'] = 2300.0;
$products['grade'] = null;

 $searchVal = array(
'[[EXAMPLE]]'
'[[EXAMPLE2]]'
);

 $replaceVal = array(
'replace word',
 $products
); 

$text = str_replace($searchVal, $replaceVal, $text);

我没有运行此代码。失败是“数组到字符串的转换”

我该怎么做。

php laravel str-replace
1个回答
0
投票

根据documentation

© www.soinside.com 2019 - 2024. All rights reserved.