首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > PHP >

请问这段内容怎么用正则 进行匹配

2012-05-27 
请教这段内容如何用正则 进行匹配form classformclass idloginform methodpost onsubmitretur

请教这段内容如何用正则 进行匹配
<form class="formclass" id="loginform" method="post" onsubmit="return loginform();">
  <div style="padding-bottom:5px">Username</div>
  <div style="padding-bottom:5px"><input type="text" name="username" style="width:180px"></div>
  <div style="padding-bottom:5px">Password</div>
  <div style="padding-bottom:5px"><input type="password" name="password" style="width:180px"></div>
   

  <div style="padding-bottom:5px"><div style="padding:5px 0px"><a href="javascript:void(0);" onclick="captchareload2();"><img src="modules/captcha/captcha.php?r=login" id="captchaimglogin" border="0"></a></div>
<script>function captchareload2(){
$("#captchaimglogin").attr('src','modules/captcha/captcha.php?r=login&x=34&y=75&z=119&?newtime=' + (new Date()).getTime());
}</script></div>
  <div style="padding-bottom:5px"><input type="text" name="captcha" id="captcha_login" style="width:180px"></div>
   
  <div style="padding-bottom:5px"><input type="submit" name="login" value="Login" class="orange"></div>
  </form>

===========================================
上面这段内容:

1、把 <div style="padding-bottom:5px"><div style="padding:5px 0px"><a href="javascript:void(0);" onclick="captchareload2();"><img src="modules/captcha/captcha.php?r=login" id="captchaimglogin" border="0"></a></div>
<script>function captchareload2(){
$("#captchaimglogin").attr('src','modules/captcha/captcha.php?r=login&x=34&y=75&z=119&?newtime=' + (new Date()).getTime());
}</script></div>,取出来,用正则匹配

2、匹配 在<form></form>里是否包含 第1点 的内容,有包含 输出真,没包含输出假

=======================================

我是在搞不懂了,请帮帮忙

[解决办法]

PHP code
 $s=<<<html <form class="formclass" id="loginform" method="post" onsubmit="return loginform();">  <div style="padding-bottom:5px">Username</div>  <div style="padding-bottom:5px"><input type="text" name="username" style="width:180px"></div>  <div style="padding-bottom:5px">Password</div>  <div style="padding-bottom:5px"><input type="password" name="password" style="width:180px"></div>      <div style="padding-bottom:5px"><div style="padding:5px 0px"><a href="javascript:void(0);" onclick="captchareload2();"><img src="modules/captcha/captcha.php?r=login" id="captchaimglogin" border="0"></a></div><script>function captchareload2(){$("#captchaimglogin").attr('src','modules/captcha/captcha.php?r=login&x=34&y=75&z=119&?newtime=' + (new Date()).getTime());}</script></div>  <div style="padding-bottom:5px"><input type="text" name="captcha" id="captcha_login" style="width:180px"></div>      <div style="padding-bottom:5px"><input type="submit" name="login" value="Login" class="orange"></div>  </form>html;preg_match('/<div style="padding-bottom:5px"><div style="padding:5px 0px">.+(?=javascript:void\(0\)).+<\/script><\/div>/s',$s,$m);print_r($m); 


[解决办法]

PHP code
$str = <<<string<form class="formclass" id="loginform" method="post" onsubmit="return loginform();">  <div style="padding-bottom:5px">Username</div>  <div style="padding-bottom:5px"><input type="text" name="username" style="width:180px"></div>  <div style="padding-bottom:5px">Password</div>  <div style="padding-bottom:5px"><input type="password" name="password" style="width:180px"></div>      <div style="padding-bottom:5px"><div style="padding:5px 0px"><a href="javascript:void(0);" onclick="captchareload2();"><img src="modules/captcha/captcha.php?r=login" id="captchaimglogin" border="0"></a></div><script>function captchareload2(){$("#captchaimglogin").attr('src','modules/captcha/captcha.php?r=login&x=34&y=75&z=119&?newtime=' + (new Date()).getTime());}</script></div>  <div style="padding-bottom:5px"><input type="text" name="captcha" id="captcha_login" style="width:180px"></div>      <div style="padding-bottom:5px"><input type="submit" name="login" value="Login" class="orange"></div>  </form>string;$pattern = "/<div style=\"padding-bottom:5px\"><div.+<\/script><\/div>/isU";preg_match_all($pattern, $str, $newstr);if($newstr[0][0]!=""){    echo $newstr[0][0];}
[解决办法]
html;要顶格写 前面不能有任何字符
http://www.php.net/manual/zh/language.types.string.php#language.types.string.syntax.heredoc

热点排行