0

In kodi Database, table tvshow, column C06 we have this kind of data :

<thumb aspect="poster">http://image.tmdb.org/t/p/original/xjm6uVktPuKXNILwjLXwVG5d5BU.jpg</thumb>
<thumb aspect="poster" type="season" season="6">http://image.tmdb.org/t/p/original/5msClP3ba8iOHvpuZjU6NyzwEB7.jpg</thumb>
<thumb aspect="poster" type="season" season="3">http://image.tmdb.org/t/p/original/xG6kJnvmGme2ZgLZASFrI1PFUnY.jpg</thumb>

I would like with a regex pattern, to extract the http:// link :

1st case -> aspect="poster" => what is the general poster of the TV show
2nd case -> season="X" => Where X is the number of the season poster i want to get

I can't get answer for this problem, i found some regex but they just extract all link, it's not possible to filter as i need, like this one :

preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $TVShowPosterString, $match);

Best regards,

S.

jaco0646
  • 15,303
  • 7
  • 59
  • 83

1 Answers1

0

It looks as though the contents is a document fragment (i.e. there isn't a single root element). So you could wrap one round the current data and then load that(I have used <data> here, but it could be anything you want)...

$data = '<thumb aspect="poster">http://image.tmdb.org/t/p/original/xjm6uVktPuKXNILwjLXwVG5d5BU.jpg</thumb>
<thumb aspect="poster" type="season" season="6">http://image.tmdb.org/t/p/original/5msClP3ba8iOHvpuZjU6NyzwEB7.jpg</thumb>
<thumb aspect="poster" type="season" season="3">http://image.tmdb.org/t/p/original/xG6kJnvmGme2ZgLZASFrI1PFUnY.jpg</thumb>';

$xml = simplexml_load_string("<data>{$data}</data>");
foreach ( $xml->thumb as $thumb )   {
    echo (string)$thumb.PHP_EOL;
}

gives the links...

http://image.tmdb.org/t/p/original/xjm6uVktPuKXNILwjLXwVG5d5BU.jpg
http://image.tmdb.org/t/p/original/5msClP3ba8iOHvpuZjU6NyzwEB7.jpg
http://image.tmdb.org/t/p/original/xG6kJnvmGme2ZgLZASFrI1PFUnY.jpg
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
  • I copy the full data row to paste bin : https://pastebin.com/ScxG1cNN when i use this, simple XML throw many error, like some special char cut all the string. – VashTester Spam Apr 27 '20 at 14:22
  • It didn't seem to have problems with the copied data. You could try `libxml_use_internal_errors(true);` before the `simplexml_load_string` and see if that suppresses the errors. – Nigel Ren Apr 27 '20 at 14:28
  • i get it working with stripslashes() thks – VashTester Spam Apr 27 '20 at 15:39