Jump to content

how to check if image is linked


nasser bahaj

Recommended Posts

 

hi all

 

is there any way to check images on my page are linked or not ?

 

example :

my page html code :

 

<html><body>
<img src="img1.gif" /><br />
<a href="www.site1.com"><img src="img2.gif" /></a><br />
<img src="img3.gif" /><br />
</body></html>

 

 

in the page above I have 3 images one of them linked and the others not linked.

 

so I want a way to get array of linked images and another array of not linked images .

 

 

array1 (
[0]=>img1.gif
[1]=>img3.gif
)

array2 (
[0]=>img2.gif
)

 

 

I think this can done by regular expression but I could not do it .

 

best regards .

Link to comment
https://forums.phpfreaks.com/topic/199896-how-to-check-if-image-is-linked/
Share on other sites

If you mean you wish a list of img tags that are locatted inside of a tags, then yes it could be done with Regex. It's possible better to do it with xpath though. At it's most basic you could write a Regex something like this...

 

<img[^>]*src="([^"]+)"[^>]*></a>

 

...to find the src value of img tags directly between </a> tags. You could improve this with lookaround assertions.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.