[英]Url Matching using Gruber's regex in PHP
如何在php中使用preg_match處理本文中提到的正則表達式?
<?php
preg_match("\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))/i", $text, $matches);
print_r($matches);
?>
使用上面的代碼我收到以下錯誤:
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash...
嘗試這個:
preg_match("#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#i", $text, $matches);
你錯過了正則表達式分隔符(通常是/
,但是在這里使用#
,因為它對URL更方便)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.