[英]php regular expression to get the specific url
我想從下面這些標記中以"http://example.com/category/"
開頭的網頁獲取網址:
<td><a href="http://example.com/category/subcategory/product/257849" title="Sample Title">Test</a></td>
注意:
257849 =隨機數
任何建議將不勝感激。
謝謝!
只需在正則表達式中指定固定的基本URL asis,然后使用[\\w/]+
匹配字母,數字和/斜杠的任意組合即可:
preg_match('#http://example.com/category/[\w/]+#', $text, $match);
print $match[0];
要一次提取所有網址,請改用preg_match_all()
。
preg_match_all('#http://example.com/category[^"]+#', $text, $a);
結果將在$ a中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.