[英]preg_match url pattern
因為我找不到我的問題的確切答案,所以我決定尋求幫助,在這里發布我的問題。 所以,我有一個頁面內容,我通過file_get_contents
獲得並希望preg_match
這個 url:
http://sample.com/Last/LastSearch.ashx?q=cnt=1&day=5&keyword=sample&location=15&view=v
從
<a href="javascript:LastURL('http://sample.com/Last/LastSearch.ashx?q=cnt=1&day=5&keyword=sample&location=15&view=v');" id="Last" rel="nofollow" class="Last" onclick="javascript:hideCss('LastCSS');hideCss('FirstRCSS');">Last</a>
請幫我。
為什么不使用 DOM? 這就是它的用途...
如果您堅持使用正則表達式,請嘗試(在 PHP 中)
if (preg_match('/<a href="javascript:LastURL\(\'([^\'])*\'/', $subject, $regs)) {
$result = $regs[1];
} else {
$result = "";
}
或(在 JavaScript 中)
var myregexp = /<a href="javascript:LastURL\('([^'])*'/;
var match = myregexp.exec(subject);
if (match != null) {
result = match[1];
} else {
result = "";
}
只要 url 總是以 http:// 開頭,那么您可以在 preg_match 中使用以下表達式:
(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.