3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Clean a partial page path of all invalid characters, * and ready it for lookup in the database. * * @param $path string The path to clean. * @return string A clean version of the path. */ function cleanPagePath($path) { $path = strtolower(rtrim($path, '/')); $tmp = ''; $pathLength = strlen($path); for ($i = 0; $i < $pathLength; $i++) { switch ($path[$i]) { case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '_': case '-': case '/': $tmp .= $path[$i]; continue; // Backslashes are looked up as forward slashes. case '\\': $tmp .= '/'; continue; // Spaces are replaced with underscores. case ' ': $tmp .= '_'; continue; default: continue; } } return $tmp; }
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /in/VcYmZ on line 58 Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /in/VcYmZ on line 63 Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /in/VcYmZ on line 68 Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /in/VcYmZ on line 71
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33

preferences:
305.08 ms | 404 KiB | 422 Q