fork download
  1. <?php
  2. $array = array("A Man of with Dignity",
  3. "A supplier *Coming*",
  4. "Break the \"Glasses\"",
  5. "Broken 'law'"
  6. );
  7.  
  8. foreach ($array as &$item) {
  9. $item = preg_replace('/\W/', '-', strtolower($item));
  10. $item = preg_replace('/-+$|^-+/', '', $item);
  11. $item = preg_replace('/-+/', '-', $item);
  12. }
  13.  
  14. print_r($array);
  15. ?>
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
Array
(
    [0] => a-man-of-with-dignity
    [1] => a-supplier-coming
    [2] => break-the-glasses
    [3] => broken-law
)