Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用str_replace时出现多个数组错误_Php_Laravel_Str Replace - Fatal编程技术网

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

Php 使用str_replace时出现多个数组错误,php,laravel,str-replace,Php,Laravel,Str Replace,我想替换如下文本 $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

我想替换如下文本

$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);
$text='1!'
[[示例]]这是一个文本
[[EXAMPLE2]]



'; $products['type']=1; $products['quantity']=2300.0; $products['grade']=null; $searchVal=数组( “[[示例]]” “[[示例2]]” ); $replaceVal=数组( “替换单词”, $products ); $text=str_replace($searchVal,$replaceVal,$text);
我没有运行此代码。此失败为“数组到字符串转换”

我如何才能做到这一点。

根据:

如果search和replace是数组,那么str_replace()将接受一个值 并使用它们来搜索和替换主题

确保
$searchVal
$replaceVal
都是线性阵列,目前它们不是

您的
$searchVal
定义缺少逗号


您的
$replaceVal
是一个数组,其中第二个元素是另一个数组。

请标记所使用的编程语言。消息很清楚:不能将数组用作字符串,可能您只需要该数组中的一个元素,例如:$products['name']我想使用多个。因为我要在html页面上解析[[EXAMPLE2]]。我想这不是我想要的方式。我必须用单人床吗?好的,我知道了。非常感谢。