2010-06-29 72 views
0

我一直在尝试下面的脚本(在一个更大的应用程序,我正在工作)现在几个小时,我只是不明白什么是问题,不管我得到什么“注意:Undefined offset:1”,这意味着它有一些问题将结果放入preg_match的数组中......我做了一个与之前的类似页面几乎相同的进程,并且它工作正常。我非常感谢任何建议,因为我现在不知道该怎么做,因为我已经花了几个小时试图解决这个问题,我没有大量的正则表达式的经验,但我已经使用了它很多,而我只是无法弄清楚什么可能会阻止它正常工作。尝试使用preg_match提取html页面,但这是令人困惑的我

<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> 
+1

我看你的代码格式挣扎......尝试选择你的代码,然后点击“代码”按钮。 – greg0ire 2010-06-29 10:10:55

+0

Rick,我突出显示了你的代码,并在编辑器中点击了格式化按钮。这并不完美(看起来像你试图手动缩进每行4个空格,但错过了一对),但它是可读的。此外,眨眼标签从哪里来? – 2010-06-29 11:00:35

+1

没有看到任何'(。*)
'子字符串在$ email_saved_pa​​ge中。 – Toto 2010-06-29 11:22:50

回答

0

更改br部分是这样的:

<br ?/?>

0

你的模式似乎是多行的,不是吗?所以你也必须使用m修饰符(请参阅here)将我的regexp设置为多行。在第二个%字符后面加'm'。

+0

对不起,只是让模式显示在帖子中正确显示很多麻烦..没有模式不是多行,只是来源是,至少我相信,我会检查以确保 – Rick 2010-06-29 10:10:58

+0

模式如何如果来源不是多行? – greg0ire 2010-06-29 10:12:45

+0

这不是多线,它只是一个像这样的字符串:“嘘通信<[email protected]>
的”从多线源获取,我不知道你是什么意思通过“我的目标是多模式源,我的模式不是多行的,如何才能做到这一点?”,我已经在没有任何问题的情况下与其他页面一起完成了这项工作,所以这对我来说似乎很陌生。 – Rick 2010-06-29 10:21:45