Php common Regular Expression instance (image address, obtained with specified content)-PHP source code

Source: Internet
Author: User
Tags preg
Revoke & quot; remove & quot; http: & quot; $ imgurl2substr ($ imgurl, 6); $ imgurl3strstr ($ im script ec (2); script

// How to extract the relative address from the remote image url and create a folder

$ Imgurl = "http://www.111cn.net/images/l/201011/sjfzgm1289209745159.jpg ";

// Remove "http :/"
$ Imgurl2 = substr ($ imgurl, 6 );

$ Imgurl3 = strstr ($ imgurl2, '/'); // This becomes: $ imgurl3 = "/images/l/201011/sjfzgm1289209745159.jpg ";

// Flip the string
$ Imgurl4 = strrev ($ imgurl3); // This becomes: $ imgurl4 = "/gpj.9515479029821mgzfjs/110102/l/segami /";
// Remove "/"
$ Imgurl4 = substr ($ imgurl3, 1); // This becomes: $ imgurl4 = "gpj.9515479029821mgzfjs/110102/l/segami /";

// Remove the file name
$ Imgurl5 = strstr ($ imgurl4, '/'); // This becomes: $ imgurl4 = "/110102/l/segami /";

// Flip and restore
$ Imgurl6 = strrev ($ imgurl5); // This becomes: $ imgurl6 = "/images/l/201011 /";

/*
This is usually the case.
There are also URLs ("")

Then obtain the relative address, first determine the domain name to find

../
./
/
The three types are directory representations.
There are just a few image extensions.

It should be written for use.

*/
// Use regular expressions to extract the content in tags


$ Str ='

Text


Text 2
';

$ Preg = '/<. +?> (. + ?) /Is ';

Preg_match_all ($ preg, $ str, $ result );

Print_r ($ result [1]);

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.