簡體   English   中英

PHP / Regex:如何替換PHP腳本中的所有字符串

[英]PHP/Regex: How to replace all Strings in PHP Script

我在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();
?>

如何使用正則表達式解決此問題? 謝謝你的幫助!

highlight_string將以PHP語法突出顯示PHP代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM