有關preg_replace_callback函數的問題

來源:互聯網
上載者:User
即php手冊preg_replace_callback函數例3
輸出

這個$input是怎麼回事?is_array($input)不是數組為什麼會輸出下面的html格式?而且去掉if(is_array($input))語句後瀏覽器firebug 的http狀態代碼出現Aborted。

運算式裡的$limit和&$count各是什嗎?百度不到?沒有案例,測試後不是很清楚


回複討論(解決方案)

前一問,應該沒有疑問
if (is_array($input)) { //如果 $input 是數組
$input = ''.$input[1].''; //則將 $input 處理成字串
}

後一問,手冊裡已經說清楚了
limit
對於每個模式用於每個subject字串的最大可替換次數. 預設是-1(無限制).

count
如果指定, 這個變數將被填充為替換執行的次數.
記錄替換的次數

前一問,應該沒有疑問
if (is_array($input)) { //如果 $input 是數組
$input = ''.$input[1].''; //則將 $input 處理成字串
}

後一問,手冊裡已經說清楚了
limit
對於每個模式用於每個subject字串的最大可替換次數. 預設是-1(無限制).

count
如果指定, 這個變數將被填充為替換執行的次數.
記錄替換的次數



但是$input = "plain [indent] deep [indent] deeper [/indent] deep [/indent] plain";不是數組array,為什麼還會可以輸出字串

return preg_replace_callback($regex, 'parseTagsRecursive', $input);
在這個語句中,$input 不應該是字串嗎?

return preg_replace_callback($regex, 'parseTagsRecursive', $input);
在這個語句中,$input 不應該是字串嗎?


我的意思是說
if (is_array($input)) {
$input = ''.$input[1].'';
}
$input不是數組array,為什麼還能輸出 $input = ''.$input[1].'';這種格式

$input = ''.$input[1].'';
是賦值!

就是將 $input 從數組變成了字串

謝謝,明白了$input在遞迴裡是完全符合。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.