Weird highlighting in php

Tony Albers tony.albers at gmx.com
Tue Oct 28 08:59:30 GMT 2025


Thanks Detlev,

 
I can live with it, it just looked strange.
 
Thanks for your help.
 
/tony
 

Sent: Tuesday, October 28, 2025 at 8:06 AM
From: "Detlev Offenbach" <detlev at die-offenbachs.de>
To: "Tony Albers" <tony.albers at gmx.com>
Subject: Re: Weird highlighting in php
Hi Tony,
thanks for giving a pointer to the source file. I looked at it and it seems, that the QScintilla HTML lexer, which is responsible for colorizing PHP code as well, cannot determine the class of the code in question. Therefore it selects the "HTML Default" or the "PHP Default". All code of QScintilla and its Lexers lies outside 'eric-ide' and is written in C/C++. If you need this changed, I recommend to post your observation on the QScintilla mailing list. Maybe Phil can do something about it.
Regards,
Detlev

Am 28.10.25 um 08:54 schrieb Tony Albers:
Hi Detlev,
 
Thanks for getting back to me.

The php stuff comes from the obstack.org project, and the file is class_totp.php
The whole application can be fetched from obstack.org


Here's the code. The weird stuff happens on line 50.
 
----------------------------snip---------------------------
      1 <?php
      2 
      3 /*
      4     TOTP v0.3.0 - a simple TOTP (RFC 6238) class
      5 
      6     (c) 2014 Robin Leffmann <djinn at stolendata dot net>
      7 
      8     https://github.com/stolendata/totp/
      9 
     10     Licensed under CC BY-NC-SA 4.0 - http://creativecommons.org/licenses/by-nc-sa/4.0/[http://creativecommons.org/licenses/by-nc-sa/4.0/]
     11 */
     12 
     13 class TOTP
     14 {
     15     private static $base32Map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
     16 
     17     private static function base32Decode( $in )
     18     {
     19         $l = strlen( $in );
     20         $n = $bs = 0;
     21 
     22         for( $i = 0; $i < $l; $i++ )
     23         {
     24             $n <<= 5;
     25             $n += stripos( self::$base32Map, $in[$i] );
     26             $bs = ( $bs + 5 ) % 8;
     27             @$out .= $bs < 5 ? chr( ($n & (255 << $bs)) >> $bs ) : null;
     28         }
     29 
     30         return $out;
     31     }
     32 
     33     public static function getOTP( $secret, $digits = 6, $period = 30, $offset = 0, $algo = 'sha1' )
     34     {
     35         if( strlen($secret) < 16 || strlen($secret) % 8 != 0 )
     36             return [ 'err'=>'length of secret must be a multiple of 8, and at least 16 characters' ];
     37         if( preg_match('/[^a-z2-7]/i', $secret) === 1 )
     38             return [ 'err'=>'secret contains non-base32 characters' ];
     39         $digits = intval( $digits );
     40         if( $digits < 6 || $digits > 8 )
     41             return [ 'err'=>'digits must be 6, 7 or 8' ];
     42         if( in_array(strtolower($algo), ['sha1', 'sha256', 'sha512']) === false )
     43             return [ 'err'=>'algo must be SHA1, SHA256 or SHA512' ];
     44 
     45         $seed = self::base32Decode( $secret );
     46         $time = str_pad( pack('N', intval($offset + time() / $period)), 8, "\x00", STR_PAD_LEFT );
     47         $hash = hash_hmac( strtolower($algo), $time, $seed, false );
     48         $otp = ( hexdec(substr($hash, hexdec($hash[-1]) * 2, 8)) & 0x7fffffff ) % pow( 10, $digits );
     49 
     50         return [ 'otp'=>sprintf("%'0{$digits}u", $otp) ];
     51     }
     52 
----------------------------snip---------------------------
 

/tony





Sent: Monday, October 27, 2025 at 1:18 PM
From: "Detlev Offenbach" <detlev at die-offenbachs.de>[mailto:detlev at die-offenbachs.de]
To: "Tony Albers" <tony.albers at gmx.com>[mailto:tony.albers at gmx.com]
Subject: Re: Weird highlighting in php
Hi Tony,
please post some PHP source to highlight the issue. As the code highlighting is done by the QScintilla editor component, which is not a part of the eric-ide code, I suspect some glitch in the lexer.
Regards,
Detlev

Am 27.10.25 um 12:39 schrieb Tony Albers:

Hi guys,
 
I'm pretty new to Eric, so please bear with me.
 
I've set up syntax highlighting for php so that it uses the same font for all text.
 
But when I'm looking at some php code in Eric, something odd is happening: The text {$digits} is shown in another font and colours than the rest of the code. See attached image.
 
What can be causing this?
 
I've looked through the other Lexer Languages in Preferences->Ediitor->Highlighters->Styles, but none of them have the shown highlighting(black text on pure white background) specified.
 
Do any of you have a suggestion on how to fix this?
 
Thanks in advance,
 
Tony
-- 
Detlev Offenbachdetlev at die-offenbachs.de[mailto:detlev at die-offenbachs.de]



More information about the Eric mailing list