正则表达式搜索页面http和https

时间:2017-03-25 17:17:53

标签: php regex http https

我有这个PHP代码:

 $cinemagiaprepare=file_get_contents("http://www.bing.com/search?q=$numele+$anul+site:https://www.cinemagia.ro/filme/&format=rss&count=1");
$cinepatern='#<\/title><link>(https:\/\/www.cinemagia.ro.+?)<\/link><description>#';
if (preg_match($cinepatern, $cinemagiaprepare, $matchc))
$numeletv1=($matchc[1]);

这是代码搜索:http://www.bing.com/search?q=Walk%20of%20Fame%202017%20site:https://www.cinemagia.ro/filme/&format=rss&count=1

此链接http://www.cinemagia.ro/filme/world-premiere-2009x00-1650809

我的代码只搜索https。我想搜索httpshttp

我试试这个正则表达式:

$cinepatern='#<\/title><link>(https.*:\/\/www.cinemagia.ro.+?)<\/link>

演示:https://regex101.com/r/oNeMMb/1此正则表达式选择所有代码。

2 个答案:

答案 0 :(得分:1)

对于https中的可选s,就是这个

'#</title><link>(https?://www\.cinemagia\.ro.+?)</link><description>#'

答案 1 :(得分:0)

使用simpleXML:

$sxe = simplexml_load_file('http://www.bing.com/search?q=$numele+$anul+site:https://www.cinemagia.ro/filme/&format=rss&count=1');

echo $sxe->xpath('//link[starts-with(., "http://www.cinemagia.ro") or starts-with(., "https://www.cinemagia.ro")]')[0];