适用于<;a id=";一些“随机文本”/&燃气轮机;在php中
我想换一个适用于<;a id=";一些“随机文本”/&燃气轮机;在php中,php,html,regex,Php,Html,Regex,我想换一个 带有空格或”。我正在使用 $a=preg_replace("/<\\/?a\\s|id(\\s+.*?>|>)/", "",$file); $a=preg_replace(“/”)/“,”,$file); 但它只删除我建议使用以下正则表达式: /(<a\s+id="[^"]*"\s*\/>)/ 当然是。正则表达式不是火箭科学。我建议您使用一些在线regex测试工具进行开发,它们非常有帮助:-) $a = preg_replace('/(<a\
带有空格
或”
。我正在使用
$a=preg_replace("/<\\/?a\\s|id(\\s+.*?>|>)/", "",$file);
$a=preg_replace(“/”)/“,”,$file);
但它只删除
我建议使用以下正则表达式:
/(<a\s+id="[^"]*"\s*\/>)/
当然是。正则表达式不是火箭科学。我建议您使用一些在线regex测试工具进行开发,它们非常有帮助:-)
$a = preg_replace('/(<a\\s+id="[^"]*"\\s*\\/>)/', '',$file);
<?php
$subject = 'test-<a id="any_text"/>-test';
$pattern = '/(<a\\s+id="[^"]*"\\s*\\/>)/';
print_r(preg_replace($pattern, '', $subject));
test--test