I am trying to parse out images from a wordpress post with get_the_content().
It returns a bunch of html and multiple lightbox shortcodes:
<ul>
<li>testing1</li>
<li>egfgf</li>
</li>
<p>Here!</p>
[lightbox link="http://www.test.com/photo1.jpg" width="150" align="none" title="photo 1" frame="true" icon="image"]
[lightbox link="http://www.test.com/photo2.jpg" width="150" align="none" title="photo 2" frame="true" icon="image"]
[lightbox link="http://www.test.com/photo5.jpg" width="150" align="none" title="photo 5" frame="true" icon="image"]
The html is not always like above and can be any html variant. My question is how can I use a regex pattern to get the link value from all the lightbox shortcodes?
Desired output:
Array
(
[0] => Array
(
[0] => http://www.test.com/photo1.jpg
[1] => http://www.test.com/photo2.jpg
[2] => http://www.test.com/photo5.jpg
)
)
Patterns I’ve tried using:
preg_match_all('/(?<![^"])S+.[^"]+/', $text, $matches);
print_r($matches);
This works on just lightbox text but when I add the html it doesnt work.
Why does my regex work on this site http://regex101.com/r/eE6fU9 but not in php?
You can use the following
See
demo