我有一個很長的html代碼串,如:<a src="this is my demo link 1 for text foo bar"/><a src="this is my demo link 2 for text foo bar"/><a src="this is my demo link 3 for text foo bar"/><a src="this is my demo link 4 for text foo bar"/>
我想在SRC所有文本鏈接=「」我使用的子字符串函數,但它給我從SRC只是第一個鏈接=「」
如何獲得全部src =「」 - >鏈接幫幫我....!如何從一個長的HTML字符串使用PHP獲取所有文本子字符串?
-3
A
回答
0
這將做你想做的。
<?php
$html = '<a src="this is my demo link 1 for text foo bar"/><a src="this is my demo link 1 for text foo bar"/><a src="this is my demo link 1 for text foo bar"/><a src="this is my demo link 1 for text foo bar"/><a src="this is my demo link 1 for text foo bar"/>';
preg_match_all('/<a[^>]+>/i', $html, $result);
$srcs=array();
foreach($result[0] as $src) {
preg_match('/src=("[^"]*")/i', $src, $result);
$srcs[] = $result[1];
}
print_r($srcs);
?>
preg_match_all在$html
字符串匹配正則表達式,並輸出一個數組$result
。我簡單地添加i
不區分大小寫。
之後,我們在$result
上運行foreach循環,並使用相同的方法抓取我們的所有$srcs
。
乾杯
+0
很高興爲您提供幫助。快樂編程! – Jesse
相關問題
- 1. 如何從字符串使用PHP獲取特定的子字符串數字?
- 2. 如何通過PHP從字符串獲取子字符串?
- 3. 從字符串獲取子字符串__
- 4. 從長字符串的某個字符開始獲取子字符串。
- 5. 如何從另一個字符串使用PHP獲取某些字符串?
- 6. 通過搜索字符串獲取子字符串文本來獲取字符串的子字符串?
- 7. PHP從字符串獲取子串
- 8. 從一個字符串獲取幾個子字符串
- 9. 從一個主字符串獲取不同的子字符串
- 10. 從javascript中的html字符串獲取子字符串
- 11. 如何從一個字符串使用C#子字符串?
- 12. 從文本中獲取子字符串
- 13. 如何從長字符串中獲取字符串?
- 14. 使用PHP從另一個字符串中提取字符串
- 15. 在JavaScript中獲取字符串的所有子字符串
- 16. 獲取字符串中所有子字符串的出現
- 17. 使用html標記從字符串中提取子字符串
- 18. 如何從另一個字符串中提取字符串php
- 19. 如何從C#中的字符串中獲取字符串的子字符串?
- 20. 獲取兩個字符串之間的子串PHP - 讀取HTML
- 21. 查找字符串中的所有3個字符長度的子字符串
- 22. 如何從另一個字符串獲取字符串值?
- 23. 如何從另一個字符串獲取字符串值
- 24. 如何從linux中的字符串獲取子字符串?
- 25. 如何從python中的字符串獲取子字符串2
- 26. 如何從給定的字符串獲取子字符串?
- 27. 如何從ColdFusion中的字符串獲取子字符串
- 28. 如何從html文本中捕獲兩個子字符串?
- 29. 獲取字符串中子字符串的第一個字母
- 30. 如何使用PHP從字符串中刪除子字符串?
感謝名單,但沒有這不是fullfil我的做法@hzq下面的答案是正確的,滿足我的慾望工作 –
請共享代碼/查詢/無論你想實現你的目標是什麼。請閱讀[幫助]中的[問]以獲得如何改善您的問題的幫助。請求代碼沒有顯示任何努力解決您的問題是爲自由職業者的網站,而不是一個問答網站。 – Pred