尝试在提取的 html 页面上使用 preg_match 但这让我感到困惑

发布于 2024-09-07 14:51:51 字数 4555 浏览 7 评论 0原文

我已经尝试下面的脚本(在我正在开发的一个更大的应用程序中)几个小时了,我只是无法理解问题是什么,无论我得到什么“注意:未定义的偏移量:1”意味着它将结果从 preg_match 放入数组时遇到一些问题...我做了一个与之前类似页面几乎相同的过程,并且工作正常..我将非常感谢任何建议,因为我只是不知道该怎么做此时,因为我已经花了几个小时尝试解决这个问题,所以我没有大量的正则表达式经验,但我已经使用了相当多的它,我只是不知道是什么可能阻止它正常工作。

 <blink>

    <?PHP

    $email_saved_page = '

    <meta name="viewport" content="width=device-width"/> 
    <title>Sign in to Hushmail Mobile</title>
    <style type="text/css">
    div#logo{padding:0.3em;}
    /* */
    body{font-family:Arial;font-size:0.8em;margin:0em;}
    h2{padding:0.3em;color:#fff;font-weight:bold;background-    color:#006699;font-       size:1.1em;margin:0em;padding-left:0.3em;}
    h2 a{color:#fff;text-decoration:none;padding:0.3em;padding-left:0em;width:100%;}
    /* */
    div.content{padding:0.4em;}
    div.menu{padding:0.3em;padding-left:0em;}
    /* */
    div.user{background-color: #D7E4F0;padding:0.5em;margin-bottom:0.5em;}
    /* */
    div.noticeContainer{padding-top:0.1em;}
    div.success{background-color:#54b067;}
    div.error{background-color:#aa4444;}
    div.info{background-color:#ff9900;}
    div.notice{padding:0.5em;color:#fff;font-weight:bold;}
    div.notice a{color:#fff;text-decoration:none;}
    /* */
    div.search_results{margin-bottom:1em;}
    div.search_results h4{margin-bottom:0em;}
    /* */
   div.listItem{border-bottom:dotted 1px #ccc;padding:0.5em;padding-left:0em;padding-    right:0em;}
   div.listItem a.subject{font-size:1.2em;}
   div.listItem div.unread{font-weight:bold;}
   span.date{color:green;}
   /* */
   div.headers{padding-top:1em;padding-bottom:1em;}
   div.headers label{font-weight:bold;}
   div.messageBodyContainer{padding-top:1em;padding-bottom:1em;}
   div.message{border-left:solid 3px #eee;padding-left:0.5em;padding-right:0.5em;}
   div.messageTruncated{background-color:#eee;padding:0.5em;}
   /* */
   .background{background-color:#f0f0f0;padding:0.3em;}
   /* */
   form#compose label.block{display:block;}
   /* */
   .copy {padding-top: 1em;color: #aaa;}

   </style>
   </head>
   <body>

   <div id="logo">
   <"/authentication?next_webapp_name=hushmail5&amp;next_webapp_url_name=m&skin=mobile">
   branding/hushmailcom/image/logo_small" border="0"/></a>
   </div>

   <h2>Sign in</h2>

   <div class="content">


   <div class="noticeContainer" id="authenticationform_hush_username"
   style="display:
   none;padding: ;width: ">
   </div>


   <div class="noticeContainer" id="authenticationform_hush_passphrase"
   style="display:
   none;padding: ;width: ">
   </div>


    <div class="noticeContainer" id="authenticationform_hush_remember_me"
    style="display:
    none;padding: ;width: ">
    </div>

   <form name="authenticationform" id="authenticationform"
    action="/authentication/login?skin=mobile&next_webapp_name=hushmail5&    amp;next_webapp_url_name=m" method="post">
   <input type="hidden" name="form_token" value="a476281f4d85"/>
   <input type="hidden" name="next_webapp_page" value="folder/INBOX/1"/>
   <p><label for="hush_username">Email address:</label><br/>
   <input type="email" name="hush_username" id="hush_username"    value="benjuuuhvvihushmailcom"/></p>
   <p><label for="hush_passphrase">Passphrase:</label><br/>
   <input type="password" name="hush_passphrase" id="hush_passphrase"  maxlength="1000"     value=""/></p>
   <p><input type="checkbox" name="hush_remember_me" id="hush_remember_me" value="on"
    /><label for="hush_remember_me">Stay signed in when I close my browser</label></p>
   <p><input type="submit" value="Sign In"/></p>
   <input type="hidden" name="hush_customerid" value="0000000000000000"/>
   </form>

   <p><a href="/m/about" title="About">About</a></p>

    <p>To learn more about Hushmail, please visit <wwwhushmailcom/" title="Hushmail -     Free    Email with Privacy"
     >wushmailc/</a> on your computer.</p>


    </div>


   <!--
   -->

   <div class="content copy">
   &copy; 2008-2010 Hush Communications Ltd.

   </div>


   ';

    $preg_string = '%<label>From:</label>(.*)<br>%' ;

    preg_match($preg_string, $email_saved_page, $res);
    $email_from = $res[1];

    echo $email_from ;

    ?>

    </blink>

I've been trying the below script (within a larger app I'm working on) for hours now and I just can't understand what the problem is, no matter what I get "Notice: Undefined offset: 1" meaning that its having some problem putting the result into an array from the preg_match... I did a process that was nearly identical to a similar page earlier and it worked fine.. I would greatly appreciate any advice as I just don't know what to do at this point as I've already spent hours trying to troubleshoot this, I don't have tons of regex experience but I have used it a fair amount and I just can't figure out what could be preventing this from working correctly.

 <blink>

    <?PHP

    $email_saved_page = '

    <meta name="viewport" content="width=device-width"/> 
    <title>Sign in to Hushmail Mobile</title>
    <style type="text/css">
    div#logo{padding:0.3em;}
    /* */
    body{font-family:Arial;font-size:0.8em;margin:0em;}
    h2{padding:0.3em;color:#fff;font-weight:bold;background-    color:#006699;font-       size:1.1em;margin:0em;padding-left:0.3em;}
    h2 a{color:#fff;text-decoration:none;padding:0.3em;padding-left:0em;width:100%;}
    /* */
    div.content{padding:0.4em;}
    div.menu{padding:0.3em;padding-left:0em;}
    /* */
    div.user{background-color: #D7E4F0;padding:0.5em;margin-bottom:0.5em;}
    /* */
    div.noticeContainer{padding-top:0.1em;}
    div.success{background-color:#54b067;}
    div.error{background-color:#aa4444;}
    div.info{background-color:#ff9900;}
    div.notice{padding:0.5em;color:#fff;font-weight:bold;}
    div.notice a{color:#fff;text-decoration:none;}
    /* */
    div.search_results{margin-bottom:1em;}
    div.search_results h4{margin-bottom:0em;}
    /* */
   div.listItem{border-bottom:dotted 1px #ccc;padding:0.5em;padding-left:0em;padding-    right:0em;}
   div.listItem a.subject{font-size:1.2em;}
   div.listItem div.unread{font-weight:bold;}
   span.date{color:green;}
   /* */
   div.headers{padding-top:1em;padding-bottom:1em;}
   div.headers label{font-weight:bold;}
   div.messageBodyContainer{padding-top:1em;padding-bottom:1em;}
   div.message{border-left:solid 3px #eee;padding-left:0.5em;padding-right:0.5em;}
   div.messageTruncated{background-color:#eee;padding:0.5em;}
   /* */
   .background{background-color:#f0f0f0;padding:0.3em;}
   /* */
   form#compose label.block{display:block;}
   /* */
   .copy {padding-top: 1em;color: #aaa;}

   </style>
   </head>
   <body>

   <div id="logo">
   <"/authentication?next_webapp_name=hushmail5&next_webapp_url_name=m&skin=mobile">
   branding/hushmailcom/image/logo_small" border="0"/></a>
   </div>

   <h2>Sign in</h2>

   <div class="content">


   <div class="noticeContainer" id="authenticationform_hush_username"
   style="display:
   none;padding: ;width: ">
   </div>


   <div class="noticeContainer" id="authenticationform_hush_passphrase"
   style="display:
   none;padding: ;width: ">
   </div>


    <div class="noticeContainer" id="authenticationform_hush_remember_me"
    style="display:
    none;padding: ;width: ">
    </div>

   <form name="authenticationform" id="authenticationform"
    action="/authentication/login?skin=mobile&next_webapp_name=hushmail5&    amp;next_webapp_url_name=m" method="post">
   <input type="hidden" name="form_token" value="a476281f4d85"/>
   <input type="hidden" name="next_webapp_page" value="folder/INBOX/1"/>
   <p><label for="hush_username">Email address:</label><br/>
   <input type="email" name="hush_username" id="hush_username"    value="benjuuuhvvihushmailcom"/></p>
   <p><label for="hush_passphrase">Passphrase:</label><br/>
   <input type="password" name="hush_passphrase" id="hush_passphrase"  maxlength="1000"     value=""/></p>
   <p><input type="checkbox" name="hush_remember_me" id="hush_remember_me" value="on"
    /><label for="hush_remember_me">Stay signed in when I close my browser</label></p>
   <p><input type="submit" value="Sign In"/></p>
   <input type="hidden" name="hush_customerid" value="0000000000000000"/>
   </form>

   <p><a href="/m/about" title="About">About</a></p>

    <p>To learn more about Hushmail, please visit <wwwhushmailcom/" title="Hushmail -     Free    Email with Privacy"
     >wushmailc/</a> on your computer.</p>


    </div>


   <!--
   -->

   <div class="content copy">
   © 2008-2010 Hush Communications Ltd.

   </div>


   ';

    $preg_string = '%<label>From:</label>(.*)<br>%' ;

    preg_match($preg_string, $email_saved_page, $res);
    $email_from = $res[1];

    echo $email_from ;

    ?>

    </blink>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑脸一如从前 2024-09-14 14:51:51

br 部分更改为如下所示:


Change the br part to something like this:

<br ?/?>

放飞的风筝 2024-09-14 14:51:51

你的模式似乎是多线的,不是吗?所以我想你也必须使用 m 修饰符将正则表达式设置为多行(请参阅 此处)。只需在第二个 % 字符后添加“m”即可。

your pattern seems to be multiline, isn't it? So you have to set your regexp as multiline too I guess, using the m modifier (see here). Just add 'm' after your second % character.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文