Guest User

Untitled

a guest
Nov 14th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. <?php
  2.  
  3. function format_uri( $string, $separator = '-' )
  4. {
  5. $accents_regex = '~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i';
  6. $special_cases = array( '&' => 'and', "'" => '');
  7. $string = mb_strtolower( trim( $string ), 'UTF-8' );
  8. $string = str_replace( array_keys($special_cases), array_values( $special_cases), $string );
  9. $string = preg_replace( $accents_regex, '$1', htmlentities( $string, ENT_QUOTES, 'UTF-8' ) );
  10. $string = preg_replace("/[^a-z0-9]/u", "$separator", $string);
  11. $string = preg_replace("/[$separator]+/u", "$separator", $string);
  12. return $string;
  13. }
  14.  
  15. echo format_uri("#@&~^!âèêëçî");
  16. //outputs : -and-aeeeci
Add Comment
Please, Sign In to add comment