Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
显示链接或URL的PHP正则表达式_Php_Wordpress_Hyperlink - Fatal编程技术网

显示链接或URL的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

我有wordpress主题,我创建了链接帖子格式,然后我希望regex php表达式只显示链接,我不想显示文本或任何摘录文本或任何图像

我创建正则表达式代码如下

$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
)