PHP Common Regular Expression instance (picture address, fetch with specified content)

Source: Internet
Author: User
Tags preg

How to extract a relative address from a remote picture URL address and create a folder

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

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

$imgurl 3 = strstr ($imgurl 2, '/'); This becomes: $imgurl 3 = = "/images/l/201011/sjfzgm1289209745159.jpg";

Next Flip the string
$imgurl 4 = Strrev ($imgurl 3); This becomes: $imgurl 4 = = "/gpj.9515479029821mgzfjs/110102/l/segami/";
Remove the "/"
$imgurl 4 = substr ($imgurl 3,1); This becomes: $imgurl 4 = = "gpj.9515479029821mgzfjs/110102/l/segami/";

Remove file name
$imgurl 5 = strstr ($imgurl 4, '/'); This becomes: $imgurl 4 = = "/110102/l/segami/";

Flip again, restore
$imgurl 6 = Strrev ($imgurl 5); This becomes: $imgurl 6 = = "/images/l/201011/";

/*
Usually the Match.
There are also URLs ("")

Then get the relative address, first judge the domain name this to find

.. /
./
/
So three kinds are the performance of the catalogue
The picture has an extension of just a few

It's supposed to be written.

*/
Use regular to extract the contents of the label


$str = ' <p> text </p>
<span> Text 2
</span> ';

$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.