0

Not all src attribute in html, Exactly the div ID begins with "post_message_"

HTML CODE

<div id="another_div">
 <img src="http://domain.com/folder/somfilename.jpg" border="0" alt="">
</div>
<div id="post_message_412">
 <img src="http://domain.com/folder/filename1.jpg" border="0" alt="">
</div>
<div id="post_message_413">
 <img src="http://domain.com/folder/filename2.jpg" border="0" alt="">
</div>
<div id="post_message_414">
 <img src="http://domain.com/folder/filename3.jpg" border="0" alt="">
</div>
<div id="post_message_415">
 <img src="http://domain.com/folder/filename4.jpg" border="0" alt="">
</div>

Get image tag's url with in the div ID begins with "post_message_" (Not like 'another_div' id name) using php preg_match() or preg_match_all() or preg_split() or any other possible solutions.

after that i want to get urls from an array

3
  • stackoverflow.com/questions/17163958/… Duplicate Commented Sep 21, 2015 at 4:43
  • This can be aced in a sec using jQuery. You'd have to use server-side script? Commented Sep 21, 2015 at 4:45
  • not all "src" attribute url in the html. exactly div ID begins with "post_message_" Commented Sep 21, 2015 at 5:24

1 Answer 1

0

Assuming the HTML is the same structure as in your example, you can use: <div\s*id="post_message_[^"]+">\s*<img src="([^"]+)

It's only long because of the literals.

  • \s* matches 0+ whitespace characters
  • [^"]+ matches characters that aren't "
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.