【问题标题】:PHP - selecting input type using REGEXPHP - 使用 REGEX 选择输入类型
【发布时间】:2017-07-09 18:34:52
【问题描述】:

我为标题道歉,我不知道如何正确表达它
但问题来了:

preg_match_all("/  (<input[^>]+>)  |  <select[^>]+>(.+?)<\/select  |  <textarea[^>]+>([^<]+)  /xims", $form, $matches);



在我正在查看的表单中,有一个文件上传输入

<input type="file" name="upload">

但是当我这样做时

print_r($matches);


我得到“文本”字段,但没有提取“文件”字段..

我也想在 $matches[] 中包含“文件”输入类型。

我的正则表达式很弱,我用谷歌搜索了很多,但没有找到准确的..
我会很感激你的回答,谢谢。

【问题讨论】:

标签: php html regex


【解决方案1】:

试试这个正则表达式:

/(?:<(select|textarea)[^>]*>[^<]+<\/\1>)|(<input[^>]*type=\"([a-z]+)\"[^>]*\/?>)/ximsg

Regex Demo

示例来源:(Run here)

$re = '/(?:<(select|textarea)[^>]*>[^<]+<\/\1>)|(<input[^>]*type=\"([a-z]+)\"[^>]*\/?>)/xims';
$str = '<input type="file" name="upload">
<input type="text" name="upload1">
<select > bla bla bla </select>
<textarea>abc</textarea>
';

preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
var_dump($matches);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-23
    • 2010-11-07
    • 2016-01-07
    • 1970-01-01
    • 2019-07-09
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    相关资源
    最近更新 更多