PHP/Regex:如何替换PHP脚本中的所有字符串

PHP/Regex:如何替换PHP脚本中的所有字符串,php,regex,Php,Regex,我在txt文件中有一个php脚本。如何为HTML创建语法突出显示。这意味着,我必须替换所有字符串,并在前面添加一个span标记,最后添加结束标记 如果我正在读取的txt文件如下所示 <?php function test() { echo "this is output" . getB() . 'another string'; } function getB() { retrurn "b"; } test(); ?> 在我的正则表达式之后应该是这样的: <

我在txt文件中有一个php脚本。如何为HTML创建语法突出显示。这意味着,我必须替换所有字符串,并在前面添加一个span标记,最后添加结束标记

如果我正在读取的txt文件如下所示

<?php
function test() {
    echo "this is output" . getB() . 'another string';
}
function getB() {
    retrurn "b";
}
test();
?>

在我的正则表达式之后应该是这样的:

<?php
function test() {
    echo <span style='color: red;'>"this is output"</span> . getB() . <span style='color: red;'>'another string'</span>;
}
function getB() {
    retrurn <span style='color: red;'>"b"</span>;
}
test();
?>

如何使用正则表达式解决此问题?谢谢你的帮助

将语法突出显示PHP代码为HTML。

将语法突出显示PHP代码为HTML。

关于“文本”或类似的内容呢?关于“文本”或类似的内容呢?