Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 正则表达式查找和替换';输入标签';_Php_Html_Regex_Replace_Find - Fatal编程技术网

Php 正则表达式查找和替换';输入标签';

Php 正则表达式查找和替换';输入标签';,php,html,regex,replace,find,Php,Html,Regex,Replace,Find,我对正则表达式很陌生,我做了试错测试 我如何替换: <input name="token" type="text" id="test" value=""> 它应该将整个value=“token”替换为所需的变量 preg_match('%]*(id=“test”[^>]*>)([^%',$html,$match); 它只搜索带有结束标记的HTML标记 例如: 对于“输入标签”的值,我提出了一个不好的解决方案 $data['token']='test'; str_替换(数组_键($d

我对正则表达式很陌生,我做了试错测试

我如何替换:

<input name="token" type="text" id="test" value="">
它应该将整个
value=“token”
替换为所需的变量

preg_match('%]*(id=“test”[^>]*>)([^%',$html,$match);

它只搜索带有结束标记的HTML标记

例如:

对于“输入标签”的值,我提出了一个不好的解决方案

$data['token']='test';

str_替换(数组_键($data)、数组_值($data)、$html);

有人能帮助我,给我一些关于PHP正则表达式的提示吗?谢谢。

试试:

<[^>]*value="(['token'"]*)"[^>]*>


Negated char class [^>] 0 to infinite times 
[greedy] matches any character except:> The character >
value=" Literal value="
1st Capturing group (['token'"]*)
Char class ['token'"] 0 to infinite times [greedy] matches:
'token'" One of the following characters 'token'"
]*value=“(['token'”]*)”[^>]*>
将字符类[^>]0求反为无限次
[贪婪]匹配除:>字符>
value=“Literal value=”
第一个捕获组(['token'”]*)
Char类['token']0到无限次[greedy]匹配:
“token”“以下字符之一”“token”“”
试试:

]*value=“(['token'”]*)”[^>]*>
将字符类[^>]0求反为无限次
[贪婪]匹配除:>字符>
value=“Literal value=”
第一个捕获组(['token'”]*)
Char类['token']0到无限次[greedy]匹配:
“token”“以下字符之一”“token”“”

不要为此使用正则表达式,而是使用HTML解析器。是的,我知道,但我只是想尝试。就像我说过的,我想尝试尝试尝试并出错。不要为此使用正则表达式,而是使用HTML解析器。是的,我知道,但我只是想尝试。就像我说过的,我想尝试尝试并出错
<[^>]*value="(['token'"]*)"[^>]*>


Negated char class [^>] 0 to infinite times 
[greedy] matches any character except:> The character >
value=" Literal value="
1st Capturing group (['token'"]*)
Char class ['token'"] 0 to infinite times [greedy] matches:
'token'" One of the following characters 'token'"