Bug #80793 [Nab]: highlight_string

From: Date: Wed, 24 Feb 2021 05:08:25 +0000
Subject: Bug #80793 [Nab]: highlight_string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232375@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80793&edit=1

 ID:                 80793
 Updated by:         requinix@php.net
 Reported by:        icarosnet at gmail dot com
 Summary:            highlight_string
 Status:             Not a bug
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   all
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

> you simply have to change the span tag for the php
Actually no, it is not that simple.

But you're missing the point. This isn't a matter of whether it *can* be done. This is a
matter of whether it *should* be done. Syntax highlighting is complicated and PHP's built-in
functionality serves the purpose as quickly as it can to some minimumm extent. Good highlighting
should allow for more customization than just the four categories PHP has (string, comment, keyword,
html), possibly even doing a certain amount of lexing beyond the initial tokenization, and
that's a lot of work to ask from the core developers for a feature that, honestly, doesn't
get used much.

This is best solved by a third-party library.

If you still feel strongly that this functionality needs to be added/improved within PHP itself,
check out the RFC process.
https://wiki.php.net/rfc/howto


Previous Comments:
------------------------------------------------------------------------
[2021-02-24 04:44:35] icarosnet at gmail dot com

well, I don't know if you can do it, to include this request in a vote, to see if they take it
out within PHP. It seems to me that it would be the same as with html, you simply have to change the
span tag for the php escapes in opening and closing, I would do it but I don't have access ...

------------------------------------------------------------------------
[2021-02-24 04:36:11] requinix@php.net

Terminal coloring varies by terminal and operating system, though cmd in Windows 10 now seems to
support the common ANSI \e[ sequences so that helps.

With a small amount of creativity, you can alter the string returned by highlight_string() to use
the proper escape sequences.

Otherwise, if there isn't already a library out there to do this for you (and I'm 95% sure
there is), the internals behind highlight_string() are not complicated so you could do it yourself
using token_get_all().
https://github.com/php/php-src/blob/PHP-8.0.3/Zend/zend_highlight.c#L84

Because honestly, this sort of thing really is best handled by a library rather than bundled into
PHP.

------------------------------------------------------------------------
[2021-02-24 04:19:47] icarosnet at gmail dot com

I am interested in this feature to run in cli, because i want implement in other of library: https://github.com/arcanisgk/BOH-Basic-Output-Handler

currently only works on web, but if "highlight_string" works correctly in CLI I can extend
the support.

------------------------------------------------------------------------
[2021-02-24 04:13:24] icarosnet at gmail dot com

i have check the php.init setting and only have this commented:

; Colors for Syntax Highlighting mode.  Anything that's acceptable in
; <span style="color: ???????"> would work.
; http://php.net/syntax-highlighting
;highlight.string  = #DD0000
;highlight.comment = #FF9900
;highlight.keyword = #007700
;highlight.default = #0000BB
;highlight.html    = #000000

the problem, not the limitation that php has in CLI is that "highlight_string" returns
html code even when run from a terminal. is there a way to do it or recreate it for CLI?

------------------------------------------------------------------------
[2021-02-24 03:59:39] requinix@php.net

Check your highlight.* php.ini settings.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=80793


--
Edit this bug report at https://bugs.php.net/bug.php?id=80793&edit=1


Thread (12 messages)

« previous php.bugs (#232375) next »