Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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_String - Fatal编程技术网

将值写入';空标签';关于PHP

将值写入';空标签';关于PHP,php,string,Php,String,我编写了一个脚本,可以搜索.html文件中的每个id= PHP: 它将跳过空标记,如id=“test2” 但我期望的结果是: WRITE 1 WRITE 2 C 将替换零件更新为: $html = preg_match('%<[^>]*(id="'.$search.'"[^>]*>)([^<]*)</[^>]*>%', $html, $match) ? str_replace($match[1] . $match[2], $match[1] .

我编写了一个脚本,可以搜索.html文件中的每个id=

PHP:

它将跳过空标记,如id=“test2”

但我期望的结果是:

WRITE 1
WRITE 2
C

将替换零件更新为:

$html = preg_match('%<[^>]*(id="'.$search.'"[^>]*>)([^<]*)</[^>]*>%', $html, $match) ? str_replace($match[1] . $match[2], $match[1] . $value,$html) : false;
$html=preg_match('%]*(id=“'.$search.”“[^>]*>)([^%',$html,$match)?str_replace($match[1]。$match[2],$match[1]。$value,$html):false;

这还将替换从ID到自身的标记的一部分。因此,您永远不会有空字符串。

将替换部分更新为:

$html = preg_match('%<[^>]*(id="'.$search.'"[^>]*>)([^<]*)</[^>]*>%', $html, $match) ? str_replace($match[1] . $match[2], $match[1] . $value,$html) : false;
$html=preg_match('%]*(id=“'.$search.”“[^>]*>)([^%',$html,$match)?str_replace($match[1]。$match[2],$match[1]。$value,$html):false;

这还将替换从ID开始到自身的标记的一部分。因此,您永远不会有空字符串。

不要尝试用正则表达式解析HTML。不要尝试用正则表达式解析HTML。
WRITE 1
WRITE 2
C
$html = preg_match('%<[^>]*(id="'.$search.'"[^>]*>)([^<]*)</[^>]*>%', $html, $match) ? str_replace($match[1] . $match[2], $match[1] . $value,$html) : false;