htcperfect

php 正则批量匹配网页文字?

  •  
  •   htcperfect · Oct 6, 2015 · 2228 views
    This topic created in 3904 days ago, the information mentioned may be changed or developed.

    就例如这样<?php
    $url = 'http://www.site.com'; //这儿填页面地址
    $info=file_get_contents($url);//初始化
    preg_match('/<title>(.?)<\/title>/',$info,$m);
    echo $m[1];
    ?>
    但是这个代码测试后发现只能匹配一个<title>(.
    ?)<\/title>里面的文字,
    如果是在一个网页里面有多个<title>...</title>,我都想提取出来该怎么修改上面代码呢

    abelyao
        1
    abelyao  
       Oct 6, 2015 via iPhone   ❤️ 1
    preg_match_all()
    现在的娃写代码都不看文档的么
    htcperfect
        2
    htcperfect  
    OP
       Oct 6, 2015
    但是我试过了,页面会出现 Array 这个词,什么都没有匹配到,其实我是想弄一个正则收集迅雷账号和密码
    代码如下
    <body>
    http://www.id97.com/tools/sharevip';//初始化 URL
    $info=file_get_contents($url); //初始化内容爬取
    preg_match_all('/'<p>(.*?)<\/p>/',$info,$account); //正则表达式获取服务器地址
    echo '<p>'.$account[1].'</p>';
    ?>
    </body>
    换成 preg_match_all 会出现 Array ,新手不太懂,谢谢回答
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3678 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 00:08 · PVG 08:08 · LAX 17:08 · JFK 20:08
    ♥ Do have faith in what you're doing.