[英]PHP/Regex: How to replace all Strings in PHP Script
I'm having a php script in a txt-file. 我在txt文件中有一个php脚本。 How i want to create a Syntax-Highlighting for HTML.
我想如何为HTML创建语法突出显示。 This means, I have to replace all strings and add a span tag in the front and the closing tag in the end.
这意味着,我必须替换所有字符串,并在前面添加一个span标签,并在最后添加结束标签。
If the txt file I'm reading looks like this 如果我正在阅读的txt文件看起来像这样
<?php
function test() {
echo "this is output" . getB() . 'another string';
}
function getB() {
retrurn "b";
}
test();
?>
It should look like this after my regex: 在我的正则表达式后应该看起来像这样:
<?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();
?>
How can I solve this using regex? 如何使用正则表达式解决此问题? Thank you for help!
谢谢你的帮助!
highlight_string将以PHP语法突出显示PHP代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.