Example of PHP Regular Expression extraction that does not contain the image address of the specified URL

Source: Internet
Author: User
Tags php regular expression
Today, when I was doing image extraction, I encountered this situation. The image in an article was extracted as the cover of the article, so that the graphic mode looks more comfortable during the layout.

Today, when I was doing image extraction, I encountered this situation. The image in an article was extracted as the cover of the article, so that the graphic mode looks more comfortable during the layout.

But now this article may contain some emotices. Of course, we cannot extract the src path strength directly. In this way, if the first one is an emoticon image, we will extract the emoticon image as the cover, at this time, we need to write a clear regular expression to exclude unmatched images. Below is a small column:

The Code is as follows:

$ Contents ='

Fatigue is a kind of enjoyment, which makes us innocent; Bumpy is an experience that makes us really understand life;
Busy is a kind of happiness, so that we do not have time to experience the pain; busy is a kind of happiness,





';

Preg_match ('#
Var_dump ($ matches );

// Running result

/*
Array (size = 2)
0 => string '1 => string 'HTTP: // www.jb51.net/uploads/image/20140420/13979336108926.jpg' (length = 66)

*/

,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.