Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.