1

I have this php code:

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

Thats code search in :http://www.bing.com/search?q=Walk%20of%20Fame%202017%20site:https://www.cinemagia.ro/filme/&format=rss&count=1

for this link http://www.cinemagia.ro/filme/world-premiere-2009x00-1650809

My code only search https. I want to search for https and http.

I try this regex:

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

Demo: https://regex101.com/r/oNeMMb/1 this regex select all code.

chris85
  • 23,846
  • 7
  • 34
  • 51
Doan
  • 21
  • 4
  • The `/` doesn't need to be escaped unless it is being used as a delimiter. Urls can also be protocol independent. You'd be best off using a parser and pulling the `link` element. – chris85 Mar 25 '17 at 17:39

2 Answers2

1

For the optional s in https, it would be this

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

0

With 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];
Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125