【问题标题】:Get links from string PHP从字符串 PHP 中获取链接
【发布时间】:2017-04-19 08:46:40
【问题描述】:

我需要一个函数来返回此字符串中视频的所有链接:

amf-editor|Joss Whedon||amf-img|<!--dle_image_begin:http://www.cpasbiens.eu/uploads/posts/2015-04/1430088868_avengers-age-of-ultrona.jpg&#124;--><img src="http://www.cpasbiens.eu/uploads/posts/2015-04/1430088868_avengers-age-of-ultrona.jpg" alt="AVENGERS: AGE OF ULTRON" title="AVENGERS: AGE OF ULTRON"  /><!--dle_image_end-->||amf-actor|Robert Downey Jr., Chris Evans, Mark Ruffalo||video1|http://videomega.tv/cdn.php?ref=048082108051120119074100048070070048100074119120051108082048&width=660&height=400||video2|https://openload.co/embed/_8xErAYN2yU/Avengers.Age.of.Ultron.2015.720p.BluRay.HD_%7C_www.onlinemovies.is_%7C.mp4||video3|http://vid.ag/embed-vxgzplvnegh8.html

For example :

$video1 = http://videomega.tv/cdn.php?  ref=048082108051120119074100048070070048100074119120051108082048&width=660&height=400

$video2 = https://openload.co/embed/_8xErAYN2yU/Avengers.Age.of.Ultron.2015.720p.BluRay.HD_%7C_www.onlinemovies.is_%7C.mp4

$video3 = http://vid.ag/embed-vxgzplvnegh8.html

谢谢

【问题讨论】:

标签: php substring


【解决方案1】:

这一行正则表达式可能会有所帮助。

function make_clickable($text) {
    $regex = '#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#';
    return preg_replace_callback($regex, function ($matches) {
        return $matches[0];
    }, $text);
}

make_clickable($video1);

【讨论】:

    猜你喜欢
    • 2013-06-03
    • 2015-08-21
    • 1970-01-01
    • 2017-09-20
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多