在PHP中查找字符串需要什么正则表达式?

问题描述 投票:-4回答:3

我试图找到字符串:

sd_src:“https://video.fhyd6-1.fna.fbcdn.net/v/t42.9040-2/10000000_2379299605422668_4104252399957311488_n.mp4?_nc_cat=1&efg=eyJybHIiOjY0OCwicmxhIjoyODQ5LCJ2ZW5jb2RlX3RhZyI6InN2ZV9zZCJ9&rl=648&vabr=360&_nc_ht=video.fhyd6-1.fna&oh=2f555df6a07d18aa1f472d972dab0114&oe=5C80FCA5

在链接https://www.facebook.com/PeinadosFacilesRapido/videos/399225660865821/的源代码中,并在PHP中打印。

看看你会理解的代码:

<?php
$sourceurl = file_get_contents('https://www.facebook.com/PeinadosFacilesRapido/videos/399225660865821/');
preg_match('REGEXP', $sourceurl, $link);
echo $link;
?>

在$ sourceurl的源代码中找到此字符串的正则表达式是什么?

php regex preg-match file-get-contents
3个回答
0
投票

您可以使用:

preg_match('~'.preg_quote($string, '~').'~i', $sourceurl, $link);

0
投票

在您的示例中,您的链接不需要由Regex查找。

你可以做 :

$sourceurl = file_get_contents('https://www.facebook.com/PeinadosFacilesRapido/videos/399225660865821/');

if ( stripos($sourceurl, $link))
{

    // do something
}

0
投票

最可靠的方法是使用HTML解析器,但这应该有效:

<?php
    $sourceurl = file_get_contents('https://www.facebook.com/PeinadosFacilesRapido/videos/399225660865821/');

    preg_match('/sd_src:"(.*?)"/s', $sourceurl, $linkArray);

    $link = $linkArray[1];

    echo $link;
© www.soinside.com 2019 - 2024. All rights reserved.