douyakan8924 2012-04-01 08:03
浏览 97
已采纳

错误:在PHP脚本中“只能通过引用传递变量”

I am having the error "Fatal error: Only variables can be passed by reference" in the following lines of code.

$ag = array(M($forge[2][$i], NULL, TRUE), M($about[0]["text"], "Less", TRUE), M($address[0]["text"], NULL, TRUE), M($phone[0]["text"], NULL, TRUE), M($website[0]["text"], "...", TRUE));

if(CAT)
    array_push($ag, M($cat[1], NULL, TRUE));

$pf_args =  str_replace("%s, ", "", PLACEHOLDER, 4 - count($_POST['ad']));

file_put_contents("files/" . FILENAME . ".sql", vsprintf($pf_args, $ag), FILE_APPEND); 

The message shows error in the last line. Can any one suggest me the reason?

(Edit): M() is defined as:

function M($text, $str = NULL, $escape = FALSE) {
    if (!empty($str))
        $text = str_replace($str, "", $text);
    $text = str_replace("(Edit)", "", $text);
    $text = str_replace("More", "", $text);
    $text = str_replace("Less", "", $text);
    $text = str_replace("<br>", "
", $text);
    if ($escape)
        return mysql_escape_string(trimText(html_entity_decode(strip_tags($text))));
    else
        return trimText(html_entity_decode(strip_tags($text)));
}
  • 写回答

1条回答 默认 最新

  • douzhi19900102 2012-04-01 08:20
    关注

    The problem is this line:

    $pf_args =  str_replace("%s, ", "", PLACEHOLDER, 4 - count($_POST['ad']));
    

    The last argument is just for outputting the number of replacements. You have to pass a variable here, not the expression 4 - count($_POST['ad']). Just remove the last argument and it will work.

    mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )

    http://php.net/manual/en/function.str-replace.php

    If you want to limit the number of replacements, there are implementations of str_replace_once in the comments of str_replace's manual page.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂