Home > Backend Development > PHP Tutorial > PHP collection problem, how to deal with multiple spaces and line breaks in the code?

PHP collection problem, how to deal with multiple spaces and line breaks in the code?

WBOY
Release: 2016-10-11 14:23:42
Original
1078 people have browsed it

The source code is:

<code><a class="figure  figure-180236 "
                                
                                                                             data-qidanadd-albumid="543438400"
                data-qidanadd-episode="0" data-qidanadd-channelid="1" data-qidanadd-tvid="543438400" data-qidanadd-vip="0" data-widget-qidanadd="qidanadd"
                 data-widget-block="block" data-block-type="qs1404043"
     data-searchpingback-elem="link"  data-searchpingback-param="ptype=1-1"                             href="http://www.iqiyi.com/v_19rr9g9wks.html?fc=87451bff3f7d2f4a#vfrm=2-3-0-1" data-playsrc-linktype="play"
                        data-playsrc-elem="pic"
            data-pb="rtgt=iqiyi&p2=9000"
 target="_blank"></code>
Copy after login
Copy after login

The collection php code is:

<code>preg_match("#<a class=\"figure  figure-180236 \" data-qidanadd-albumid=\"543438400\" data-qidanadd-episode=\"0\" data-qidanadd-channelid=\"1\" data-qidanadd-tvid=\"543438400\" data-qidanadd-vip=\"0\" data-widget-qidanadd=\"qidanadd\" data-widget-block=\"block\" data-block-type=\"qs1404043\" data-searchpingback-elem=\"link\" data-searchpingback-param=\"ptype=1-1\" href=\"(.*?)\" data-playsrc-linktype=\"play\" data-playsrc-elem=\"pic\" data-pb=\"rtgt=iqiyi&p2=9000\" target=\"_blank\">#",$content,$array);</code>
Copy after login
Copy after login

But the information cannot be collected in this case? Solve

Reply content:

The source code is:

<code><a class="figure  figure-180236 "
                                
                                                                             data-qidanadd-albumid="543438400"
                data-qidanadd-episode="0" data-qidanadd-channelid="1" data-qidanadd-tvid="543438400" data-qidanadd-vip="0" data-widget-qidanadd="qidanadd"
                 data-widget-block="block" data-block-type="qs1404043"
     data-searchpingback-elem="link"  data-searchpingback-param="ptype=1-1"                             href="http://www.iqiyi.com/v_19rr9g9wks.html?fc=87451bff3f7d2f4a#vfrm=2-3-0-1" data-playsrc-linktype="play"
                        data-playsrc-elem="pic"
            data-pb="rtgt=iqiyi&p2=9000"
 target="_blank"></code>
Copy after login
Copy after login

The collection php code is:

<code>preg_match("#<a class=\"figure  figure-180236 \" data-qidanadd-albumid=\"543438400\" data-qidanadd-episode=\"0\" data-qidanadd-channelid=\"1\" data-qidanadd-tvid=\"543438400\" data-qidanadd-vip=\"0\" data-widget-qidanadd=\"qidanadd\" data-widget-block=\"block\" data-block-type=\"qs1404043\" data-searchpingback-elem=\"link\" data-searchpingback-param=\"ptype=1-1\" href=\"(.*?)\" data-playsrc-linktype=\"play\" data-playsrc-elem=\"pic\" data-pb=\"rtgt=iqiyi&p2=9000\" target=\"_blank\">#",$content,$array);</code>
Copy after login
Copy after login

But the information cannot be collected in this case? Solve

Please study PHP's regular expression mode carefully. There is an m in it which means multi-line matching can meet your needs, http://php.net/manual/en/refe....

It is recommended to use DiDom for html parsing
Similar to jquery’s dom selection

In the final analysis, you just want to get the href link address of the hyperlink, right? You have written too many regular expressions. The more you write, the harder it is to match. In addition, multi-line matching has special pattern matching characters as mentioned above. I Generally used is s

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template