preg_match表单中输入字段的名称 [英] preg_match name of input field inside form

查看:107
本文介绍了preg_match表单中输入字段的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我花了2个小时试图preg_match这个表单

 < form class =form-searchmethod =postaction =/ index.php> 
< div class =form-group>
< input id =address_boxtype =textclass =form-controlname =xvalue =onfocus =this.select()/>
< / div>
< span class =btn btn -s btn-caps>< input type =submitvalue =start/>< / span>
< / form>

收件人:

  Preg_match:

START =< form

WHERE action CONTAIN /index.php
EX:action =/ index.php或action =http://whatever.com/index.php

FIND name =[A-Za-z] {1}

END =< /形式>

然后输出[A-Za-z] {1}匹配(应该得到x)

请问我该怎么做?



谢谢。

解决方案 $ p
$ b $ $ $ regex ='/< form。*( ?< = ACTION = \ )\ / index.php\? > *(小于?=名= \)([A-ZA-Z] {1})(=? \)* LT; \?/形式> /秒;


Sorry, i spent like 2 hours trying to preg_match this form

<form class="form-search" method="post" action="/index.php">
  <div class="form-group">
    <input id="address_box" type="text" class="form-control" name="x" value="" onfocus="this.select()" />
  </div>
<span class="btn btn-s btn-caps"><input type="submit" value="start" /></span>
</form>

To:

Preg_match:

START = <form

WHERE action CONTAIN /index.php
EX: action="/index.php" or action="http://whatever.com/index.php"

FIND name="[A-Za-z]{1}"

END = </form>

Then Output the [A-Za-z]{1} Match (Should get x)

How can i do it correctly please?

Thanks.

解决方案

Ok, this regex should do the job:

$regex = '/<form.*(?<=action=\")?\/index.php\">.*(?<=name=\")([A-Za-z]{1})(?=\").*?<\/form>/s';

这篇关于preg_match表单中输入字段的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆