Edit report at https://bugs.php.net/bug.php?id=80793&edit=1
ID: 80793
User updated by: icarosnet at gmail dot com
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:
Thanks a lot; I have made a small adaptation to my library based on what you have shared with me and
I see that it works partially, I will do my part and verify what is not working correctly. I leave
you the image of the output by cli:
https://i.imgur.com/vjBjuVQ.png
Previous Comments:
------------------------------------------------------------------------
[2021-02-24 05:54:17] requinix@php.net
https://gist.github.com/requinix/6895f9abeb90022f729a8b58a160be60
------------------------------------------------------------------------
[2021-02-24 05:23:58] requinix@php.net
Please re-read the documentation for token_get_all.
https://www.php.net/token-get-all
If you have any more questions about your code, see
https://www.php.net/support.php
------------------------------------------------------------------------
[2021-02-24 05:19:18] icarosnet at gmail dot com
I have verified both the Zend engine topic and the get all token function; but when trying to
implement it I get an error:
Warning: token_name() expects parameter 1 to be int, string given in
C:\xampp\htdocs\dev\t5\BOH-Basic-Output-Handler\src\OutputHandler.php on line 320
NULL
string(1) "="
Warning: token_name() expects parameter 1 to be int, string given in
C:\xampp\htdocs\dev\t5\BOH-Basic-Output-Handler\src\OutputHandler.php on line 320
NULL
string(1) "["
Do you have any idea how to solve the error of these signs?
The code you run to test is as follows:
$test = '
<?php ' . PHP_EOL . '
$array=["data1","data2"];
' . PHP_EOL . ' ?>
';
$tokenstring = token_get_all($test);
foreach ($tokenstring as $key => $arraytoken) {
$tokenname = token_name($arraytoken[0]);
echo '<pre>';
echo var_dump($tokenname, $arraytoken);
echo '</pre>';
}
------------------------------------------------------------------------
[2021-02-24 05:08:25] requinix@php.net
> 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
------------------------------------------------------------------------
[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 ...
------------------------------------------------------------------------
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