Q
只得到第一行
0
A
回答
1
<?php
if (preg_match('/error_id: (\d+)/', $string, $matches)) {
print_r($matches);
}
我想你會想利用$matches[1]
但我不記得手!
1
<?php
// Your string.
$string = 'error_id: 44 error_de: wrong number : 565';
// Find the error id from your string ($string).
if(preg_match('/error_id\:\s+([\d]+)/', $string, $matches))
{
// Echo out the error id number
echo $matches[1];
}
有關preg_match的更多信息,請參閱http://php.net/manual/en/function.preg-match.php。
1
您需要使用的preg_match _all因爲有不止一個
preg_match_all("/error_id:\s+(\d+)/", $theString, $errorIDs);
Var_dump($errorIDs[1]);
工作爲例,點擊preg_match_all
http://www.phpliveregex.com/p/fMH
編輯(如果我理解正確嗎?):如果你需要「錯誤的數字」部分也使用此模式:error_id:\s+(\d+).error_de: (.*) : (\d+)
相關問題
- 1. 搜尋++只得到的第一行
- 2. 只得到第一個元素
- 3. 的selectNodes只得到第一個節點
- 4. 只得到第一級子目錄C#
- 5. Git FileRevision用多行獲得評論 - 只獲得第一行
- 6. PHP的XPath評估重複數據只得到第一行
- 7. Crontab只執行第一行
- 8. 得到的第一行加入
- 9. XML到CSV,只能獲得一行?
- 10. Javascript複製到剪貼板只得到第一個記錄
- 11. xlsread只有第一行
- 12. SQL只選擇第一行
- 13. SSRS只顯示第一行
- 14. Python readline - 只讀第一行
- 15. GZipStream只解壓第一行
- 16. Python只打印第一行
- 17. Sql_Srv只返回第一行
- 18. TSQL只顯示第一行
- 19. 欄只選擇第一行
- 20. LEFT JOIN只有第一行
- 21. MySQL只插入第一行
- 22. Phonegap - Filewriter只寫第一行
- 23. Java FileWriter只寫第一行
- 24. StreamWriter的只寫第一行
- 25. Dockerfile中只讀第一行
- 26. Apache Camel只讀第一行
- 27. fGetCsv只讀第一行?
- 28. 只得到一個DOM XPath查詢的第一個結果
- 29. jquery filter:只獲得第一個匹配?
- 30. JQuery - 只獲得第一輪子孫
'preg_match('〜error_id:\ s * \ K \ d +〜',$ string)' –
包括'erro r_de'以及? – chris85