Enrico Baldi
Enrico Baldi

Reputation: 3

Regex PHP to extract a photo gallery from an HTML string

In my HTML page I have multiple occurrences of this code:

<a onclick="window.open('hxxp://www.mysite.com/gallery/foto_amatoriali/foto_gallery_prova/foto_amatoriali.jpg');" href="javascript:void(0)">
    <img height="90" alt="foto_amatoriali.jpg" src="hxxp://www.mysite.com/gallery/foto_amatoriali/foto_gallery_prova/th/foto_amatoriali_thumb.jpg" width="120" vspace="4" />
</a>

What I wanna do is with php extract all IMAGE SOURCES LINK

hxxp://www.mysite.com/gallery/foto_amatoriali/foto_gallery_prova/foto_amatoriali.jpg

Between window.open(' and ');

I created this REGEX PATTERN:

open\(\'([^()]*)\'

I tested via an online REGEX edtior and it seems to work but when I do it via php it works not correctly.

In many case it extract not only the link but LINK plus window.open('

Someone can help me with the correct REGEX syntax ?

Thanks

Upvotes: 0

Views: 71

Answers (1)

Croises
Croises

Reputation: 18671

You can use this regex:

(?<=open\(\')([^()]*)(?=\'\))

Upvotes: 1

Related Questions