开发者

Getting the first image url from a post? [duplicate]

This question already has an answer here: Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜