Conversation
| foreach ($stringExplode as $string) { | ||
| if (strpos($string, 'user_') === 0) { | ||
| $accessArray['users'][] = substr($string, 5); | ||
| $accessArray['users'][] = mb_substr($string, 5); |
There was a problem hiding this comment.
this is not really necessary, as you already checked that the first 5 chars are user_ which are not utf8 sensible anyway.
Same below
There was a problem hiding this comment.
Ah, ok, so it is only necessary, where i count and only if my text needs to be reasonable afterwards...^^ 👍
There was a problem hiding this comment.
Any drawback of using it anyways?
There was a problem hiding this comment.
its a lot slower (factor 4), but well I guess in form (migration) it doesn't matter at the moment:
$start = microtime(true);
for ($i = 0; $i < 100000; $i++) {
substr('Лорем', 2);
}
var_dump(microtime(true) - $start); // float(0.008073091506958008)
$start = microtime(true);
for ($i = 0; $i < 100000; $i++) {
mb_substr('Лорем', 2);
}
var_dump(microtime(true) - $start); // float(0.035883188247680664)Well you should use it whenever the string part you are counting/cutting contains such characters. see this:
https://3v4l.org/licri
// No difference:
var_dump(strlen('user_')); // int(5)
var_dump(mb_strlen('user_')); // int(5)
var_dump(substr('user_', 0, 2)); // string(2) "us"
var_dump(mb_substr('user_', 0, 2)); // string(2) "us"
var_dump(substr('user_', 2)); // string(2) "er_"
var_dump(mb_substr('user_', 2)); // string(2) "er_"
// Difference:
var_dump(strlen('Лорем')); // int(10)
var_dump(mb_strlen('Лорем')); // int(5)
var_dump(substr('Лорем', 0, 2)); // string(2) "Л"
var_dump(mb_substr('Лорем', 0, 2)); // string(4) "Ло"
var_dump(substr('Лорем', 2)); // string(8) "орем"
var_dump(mb_substr('Лорем', 2)); // string(6) "рем"
// This breaks your database because of the invalid char
var_dump(substr('Лорем', 3)); // string(7) "�рем"
var_dump(mb_substr('Лорем', 3)); // string(4) "ем"There was a problem hiding this comment.
Interesting. Thank you! :)
Signed-off-by: Jonas Rittershofer <jotoeri@users.noreply.github.com>
|
@skjnldsv Maybe a patch-release is useful? 🤔 |
Agreed! |
There are still some substr occurences on license.php, which i left out for the moment... Not sure if it is good to change anything there?
Should fix #527