显示链接或URL的PHP正则表达式
我有wordpress主题,我创建了链接帖子格式,然后我希望regex php表达式只显示链接,我不想显示文本或任何摘录文本或任何图像 我创建正则表达式代码如下显示链接或URL的PHP正则表达式,php,wordpress,hyperlink,Php,Wordpress,Hyperlink,我有wordpress主题,我创建了链接帖子格式,然后我希望regex php表达式只显示链接,我不想显示文本或任何摘录文本或任何图像 我创建正则表达式代码如下 $pattern = '/.*?(http\:\/\/www\.[a-zA-Z0-9\.\/\-]+)/'; $subject = get_the_content(); preg_match_all($pattern, $subject, $matches); print_r($matches); 但此代码不会返回到任何链接或UR
$pattern = '/.*?(http\:\/\/www\.[a-zA-Z0-9\.\/\-]+)/';
$subject = get_the_content();
preg_match_all($pattern, $subject, $matches);
print_r($matches);
但此代码不会返回到任何链接或URL。请帮助我,我希望模式仅返回或打印链接。您是否试图从
$subject
提取所有URL?如果是这样,请尝试以下方法:
$subject = "Lorem ipsum dolor sit amet, http://example1.com consectetur adipisicing elit, http://example2.com";
preg_match_all('#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $subject, $matches);
$all_urls = $matches[0];
print_r($all_urls);
您的模式显示此错误preg\u match\u all():未知修饰符“/”
Array
(
[0] => http://example1.com
[1] => http://example2.com
)