Here is an example code snippet that uses PHP regular expressions to match and replace all `<a>` tags:
<?php
// 假设这是要替换的 HTML 代码
$html = '<p><a href="https://example.com">Link 1</a></p><p><a href="https://example.com">Link 2</a></p>';
// 使用正则表达式进行匹配和替换
$new_html = preg_replace('/<a\s.*?>(.*?)<\/a>/', '$1', $html);
// 输出新的 HTML 代码
echo $new_html;
?>In the above example code, we use preg_replace Use a function to replace all <a> tags. Regular expression /<a\s.*?>(.*?)<\/a>/ Matches the entire <a> tag and uses a non-greedy matching mode to extract the text within the tag. Replacement section. $1 It retains the text content from the `a` tag, thereby achieving a replacement effect.
Running the above code will output the following result:
<p>Link 1</p><p>Link 2</p>As you can see, all <a> tags have been successfully replaced with plain text content.