<?php
$test_cases = array(
"abc.txt" => '.',
"https://3v4l.org/?foo" => '?',
"https://3v4l.org/#bar" => '#',
$_SERVER['PATH'] => ':',
"PHP 8.3.8" => ' ',
"192.168.1.1" => '.',
"foo\nbar" => "\n",
"snake_case" => '_',
);
foreach ($test_cases as $string => $char) {
if (strtok($string,$char)==pathinfo($string, PATHINFO_FILENAME)) {
echo "\n\nSUCCESS: {$string} => {$char}";
} else {
$string = str_replace("\n","\\n",$string);
$char = str_replace("\n","\\n",$char);
echo "\n\nFAILED: {$string} => {$char}";
echo "\n- strtok(): " . strtok($string,$char);
echo "\n- pathinfo(): " . pathinfo($string, PATHINFO_FILENAME);
};
}
- Output for 8.1.29 - 8.1.30, 8.2.19 - 8.2.25, 8.3.5 - 8.3.14
- SUCCESS: abc.txt => .
FAILED: https://3v4l.org/?foo => ?
- strtok(): https://3v4l.org/
- pathinfo(): ?foo
FAILED: https://3v4l.org/#bar => #
- strtok(): https://3v4l.org/
- pathinfo(): #bar
FAILED: /usr/bin:/bin => :
- strtok(): /usr/bin
- pathinfo(): bin
FAILED: PHP 8.3.8 =>
- strtok(): PHP
- pathinfo(): PHP 8.3
FAILED: 192.168.1.1 => .
- strtok(): 192
- pathinfo(): 192.168.1
FAILED: foo\nbar => \n
- strtok(): foo
- pathinfo(): foo\nbar
FAILED: snake_case => _
- strtok(): snake
- pathinfo(): snake_case
preferences:
48.26 ms | 409 KiB | 5 Q