2012-04-01 57 views
0

我在以下代码行中发生错误“致命错误:只能通过引用传递变量”。错误:PHP脚本中只能通过引用传递变量

$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); 

该消息在最后一行显示错误。任何人都可以告诉我原因?

(编辑):M()被定义为:

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>", "\n", $text); 
    if ($escape) 
     return mysql_escape_string(trimText(html_entity_decode(strip_tags($text)))); 
    else 
     return trimText(html_entity_decode(strip_tags($text))); 
} 
+3

究竟在哪一行? “M”如何定义? – Gumbo 2012-04-01 08:06:02

+0

@Gumbo:file_put_contents()和M()只做了很少的字符串替换。 – Shubham 2012-04-01 08:10:18

+1

怎么样显示M代码 – SergeS 2012-04-01 08:16:34

回答

6

问题是这样的线:

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

最后一个参数是只用于输出的替换数。你必须在这里传递一个变量,而不是表达式。只要删除最后一个参数,它就会起作用。

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

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

如果你想限制更换的次数,还有在str_replace的手册页的评论str_replace_once实现。

+0

我很遗憾听到,你不打开建设性的批评。 – Basti 2012-04-01 08:37:53

+0

str_replace_once ::工作,但需要重写脱衣舞娘:) – user956584 2012-05-01 21:16:41