-1

我正在尝试制作一个很酷的 php 函数来替换东西,但由于不明原因而出现解析错误。我错过了什么吗?

error_reporting(E_ALL);

$array_pairs  = array( '{{simple}}' => 'simple_value', '{{organization}}' => 'Apple Inc');


function the_replace($aray_pairs,  $content){
foreach($aray_pairs as $a => $b)
{
$content = str_replace($a, $b, $content);

 return $content;
}


$invoice = '{{organization}} is a {{simple}}';

$invoice = replace_values($array_pairs, $invoice);
echo $invoice;
4

1 回答 1

1

缺少 } 函数名称也不匹配

error_reporting(E_ALL);

$array_pairs  = array( '{{simple}}' => 'simple_value', '{{organization}}' => 'Apple Inc');


function replace_values($aray_pairs,  $content){ // function names didn't match too.
   foreach($aray_pairs as $a => $b)
   {
       $content = str_replace($a, $b, $content);

   }
   return $content;

} // here

$invoice = '{{organization}} is a {{simple}}';

$invoice = replace_values($array_pairs, $invoice);
echo $invoice;
于 2013-04-01T18:47:09.830 回答