Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. function slug($text){
  2.  
  3. // replace non letter or digits by -
  4. $text = preg_replace('~[^pLd]+~u', '-', $text);
  5.  
  6. // transliterate
  7. $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
  8.  
  9. // remove unwanted characters
  10. $text = preg_replace('~[^-w]+~', '', $text);
  11.  
  12. // trim
  13. $text = trim($text, '-');
  14.  
  15. // remove duplicated - symbols
  16. $text = preg_replace('~-+~', '-', $text);
  17.  
  18. // lowercase
  19. $text = strtolower($text);
  20.  
  21. if (empty($text)) {
  22. return 'n-a';
  23. }
  24.  
  25. return $text;
  26. }
  27.  
  28. function filterSlug($ax, $bx){
  29. if(isset($_POST[$ax]) && $_POST[$ax] != ''){
  30. $ax = slug($ax);
  31. } else {
  32. $ax = slug($bx);
  33. }
  34. }
  35.  
  36. filterSlug($postSlug, $postTitle);
  37.  
  38. if(isset($_POST['postSlug']) && $_POST['postSlug'] != ''){
  39. $postSlug = slug($postSlug);
  40. } else {
  41. $postSlug = slug($postTitle);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement