看板 PHP 關於我們 聯絡資訊
※ 引述《rj5871224 (5871224)》之銘言: : 想抓網頁上某個字串出現的次數 : 有沒有簡單的語法可以做到呢? 如果簡單的字串的話,可能會輸 str* 系列的 function 不過你希望是「簡單」的語法,我剛剛測了一下,還滿簡單的 XD $string = '123 456 123 123 123 456 1234 123456 12 '; // 列出符合數目 print_r(preg_match_all('/123/', $string, $matches)); // result: 6 // 你可以改成 $count = preg_match_all 就好 // preg_match_all 的 return 說明如下 // Returns the number of full pattern matches (which might be zero), // or FALSE if an error occurred. // 把他們列出來看看(不過沒什麼好看的)= = print_r($matches); /* : Array : ( : [0] => Array : ( : [0] => 123 : [1] => 123 : [2] => 123 : [3] => 123 : [4] => 123 : [5] => 123 : ) : ) */ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.145.202.66