2012-04-01 97 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

相關問題