In what situations would it be more beneficial to write a custom code highlighter in PHP rather than using existing libraries or scripts?

In situations where existing libraries or scripts do not meet the specific requirements or customization needed for code highlighting, it would be more beneficial to write a custom code highlighter in PHP. This allows for greater control over the highlighting process and the ability to tailor it to fit the specific needs of the project.

<?php
function customCodeHighlighter($code) {
    // Custom code highlighting logic goes here
    // This function can be customized to apply specific styles or formatting to different code elements
    return $highlightedCode;
}

$code = "function helloWorld() {
    echo 'Hello, World!';
}";

$highlightedCode = customCodeHighlighter($code);
echo $highlightedCode;