3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function slugify($title) { $output = ''; $valid_characters = 'abcdefghijklmnopqrstuvwxyz1234567890'; $len = strlen($title); for ($i = 0;$i < $len;$i++) { if (stripos($valid_characters, $title[$i]) !== FALSE) { // Letters and numbers are valid $output .= strtolower($title[$i]); } elseif ($i > 0 && $title[$i] !== '\'' && stripos($valid_characters, $title[$i - 1]) !== FALSE) { // Other characters are turned into dashes, but never two // in a row. $output .= '-'; } } if (substr($output, -1, 1) === '-') { return substr($output, 0, -1); } else { return $output; } } echo slugify('This is not a love song').PHP_EOL; echo slugify('There\'s a lady who is sure').PHP_EOL; echo slugify('All that is gold does not glitter ').PHP_EOL;
Output for 5.0.2 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
this-is-not-a-love-song theres-a-lady-who-is-sure all-that-is-gold-does-not-glitter
Output for 5.0.0 - 5.0.1
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/vHrcO on line 26 this-is-not-a-love-songPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/vHrcO on line 27 theres-a-lady-who-is-surePHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/vHrcO on line 28 all-that-is-gold-does-not-glitterPHP_EOL
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: stripos() in /in/vHrcO on line 9
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: stripos() in /in/vHrcO on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: stripos() in /in/vHrcO on line 9