Getting the first image url from a post? [duplicate]
Possible Duplicate:
Geting the first image url from a post?
I am trying to create a dynamic websi开发者_如何学Pythonte, I have a database with some news, and I wanted to get the first image from the post content, the images are at my database, not an external one.
How can I get the first image of the post and display the link?
It depends on how the news is stored (HTML?). But an easy way is to just go through the markup character by character until you hit the first image (in HTML, this would be denoted by a <img />
tag.
You can use strpos()
to find the first occurrence of a substring in a string. And then you can use substr()
to extract the image.
精彩评论