<?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;
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.3.11, 4.4.0 - 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