Florian Müller
Florian Müller

Reputation: 7785

PHP/Regex: How to replace all Strings in PHP Script

I'm having a php script in a txt-file. How i want to create a Syntax-Highlighting for HTML. This means, I have to replace all strings and add a span tag in the front and the closing tag in the end.

If the txt file I'm reading looks like this

<?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!

Upvotes: 0

Views: 229

Answers (1)

Ramon
Ramon

Reputation: 8424

highlight_string will syntax-highlight PHP code as HTML.

Upvotes: 3

Related Questions