preg_match 表单内输入字段的名称
preg_match name of input field inside form
抱歉,我花了将近 2 个小时来 preg_match 这个表格
<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>
收件人:
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)
请问如何正确操作?
谢谢。
$pat = /\/index.php\">.*?form-control\".*(?<=name=\")([A-Za-z]{1})(?=\")/s
$sub = '<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>';
preg_match($pat,$sub,$match);
to echo mateched use echo $match[1];
好的,这个正则表达式应该可以完成工作:
$regex = '/<form.*(?<=action=\")?\/index.php\">.*(?<=name=\")([A-Za-z]{1})(?=\").*?<\/form>/s';
抱歉,我花了将近 2 个小时来 preg_match 这个表格
<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>
收件人:
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)
请问如何正确操作?
谢谢。
$pat = /\/index.php\">.*?form-control\".*(?<=name=\")([A-Za-z]{1})(?=\")/s
$sub = '<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>';
preg_match($pat,$sub,$match);
to echo mateched use echo $match[1];
好的,这个正则表达式应该可以完成工作:
$regex = '/<form.*(?<=action=\")?\/index.php\">.*(?<=name=\")([A-Za-z]{1})(?=\").*?<\/form>/s';