RegEx for <a id="Some_Random_Text"/> in php


RegEx for <a id="Some_Random_Text"/> in php

我想替换 <a id="any_text"/> space""。我正在使用

$a=preg_replace("/<''/?a''s|id(''s+.*?>|>)/", "",$file);

但它只会消除<a

我建议使用这个正则表达式:

/(<a's+id="[^"]*"'s*'/>)/

这将导致该命令:

$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