这就是:如果eregi()无法匹配,则$outdata赋值将永远不会发生,因为if块将不会执行。如果它匹配,但标签之间没有任何内容,$outdata将被分配一个空字符串。在两种情况下,!$outdata都将是真的,所以我们可以回退到标题标签上进行第二次匹配。
if(eregi("<linkto>(.*?)</linkto>", $string, $link_match)) {
$outdata = $link_match[1];
}
if(!$outdata && eregi("<title>(.*?)</title>", $string, $title_match)) {
$outdata = $title_match[1];
}
我也将匹配中的(.*)改成了(.*?)。这意味着不要贪心。在(.*)的形式中,如果$string设置为
<title>Page Title</title> I am sorry, but you did not provide any text or phrase for me to translate into Chinese. Please provide me with the correct text or phrase that you want me to translate.
I am sorry, but you did not provide any text or phrase for me to translate into Chinese. Please provide me with the correct text or phrase that you want me to translate. <iframe><title>A second title tag!</title></iframe>
正则表达式将匹配
Page Title</title> I am sorry, but you did not provide any text or phrase for me to translate into Chinese. Please provide me with the correct text or phrase that you want me to translate. I am sorry, but you did not provide any text or phrase for me to translate into Chinese. Please provide me with the correct text or phrase that you want me to translate. <iframe><title>A second title tag!
因为它尝试尽可能地匹配,只要文本位于任何<和>之间! 在(.?*)表单中,匹配会如您所期望地执行 - 它会匹配。
Page Title
一旦可能就停止。
I am sorry, but you did not provide any text or phrase for me to translate into Chinese. Please provide me with the correct text or phrase that you want me to translate.
顺便说一句,这个东西是个有趣的方案,但你为什么需要它?页面可以通过查询字符串链接到其他页面并传递参数。
<a href="somescript.php?prevpage=Foo">I am sorry, but you did not provide any text or phrase for me to translate into Chinese. Please provide me with the correct text or phrase that you want me to translate.</a>
然后,somescript.php可以通过$_GET[prevpage]超全局变量访问prevpage参数。
那樣做能解決你的問題嗎? (nà yàng zuò néng jiějué nǐ de wèntí ma?)