-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsyntax.php
More file actions
18 lines (16 loc) · 871 Bytes
/
Copy pathsyntax.php
File metadata and controls
18 lines (16 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
function highlightText($text) {
$text = trim($text);
$text = highlight_string("<?php " . $text, true); // highlight_string() requires opening PHP tag or otherwise it will not colorize the text
$text = trim($text);
$text = preg_replace("|^\\<code\\>\\<span style\\=\"color\\: #[a-fA-F0-9]{0,6}\"\\>|", "", $text, 1); // remove prefix
$text = preg_replace("|\\</code\\>\$|", "", $text, 1); // remove suffix 1
$text = trim($text); // remove line breaks
$text = preg_replace("|\\</span\\>\$|", "", $text, 1); // remove suffix 2
$text = trim($text); // remove line breaks
$text = preg_replace("|^(\\<span style\\=\"color\\: #[a-fA-F0-9]{0,6}\"\\>)(<\\?php )(.*?)(\\</span\\>)|", "\$1\$3\$4", $text); // remove custom added "<?php "
return $text;
}
$code = file_get_contents('c.cpp');
echo highlightText($code);
?>