Created
April 26, 2018 06:38
-
-
Save relliv/1cbf290a1b811b3f14d36665fd6edd88 to your computer and use it in GitHub Desktop.
Content Based Sef Link Fonctions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*--------------------- SEF Link ----------------- START */ | |
// Conversation title to better link string | |
public function sefLink($str){ | |
$str = $this->parentSefLink($str); | |
if ($str !== mb_convert_encoding(mb_convert_encoding($str, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32')) | |
$str = mb_convert_encoding($str, 'UTF-8', mb_detect_encoding($str)); | |
$str = htmlentities($str, ENT_NOQUOTES, 'UTF-8'); | |
$str = preg_replace('`&([a-z]{1,2})(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig);`i', '1', $str); | |
$str = html_entity_decode($str, ENT_NOQUOTES, 'UTF-8'); | |
$str = preg_replace(array('`[^a-z0-9]`i', '`[-]+`'), '-', $str); | |
$str = strtolower(trim($str, '-')); | |
return $str; | |
} | |
// helper function comes first | |
// for turkish characters replacing | |
public function parentSefLink($string) | |
{ | |
$turkce=array("ş", "Ş", "ı", "ü", "Ü", "ö", "Ö", "ç", "Ç", "ğ", "Ğ", "İ", "I"); | |
$duzgun=array("s", "s", "i", "u", "u", "o", "o", "c", "c", "g", "g", "i", "i"); | |
$string = str_replace($turkce, $duzgun, $string); | |
$string = trim($string); | |
$string = html_entity_decode($string); | |
$string = strip_tags($string); | |
$string = strtolower($string); | |
$string = preg_replace('~[^ a-z0-9_.]~', ' ', $string); | |
$string = preg_replace('~ ~', '-', $string); | |
$string = preg_replace('~-+~', '-', $string); | |
return $string; | |
} | |
/*--------------------- SEF Link ----------------- END */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TR- | |
Call: ..sefLink("pijamalı hasta yağız şoföre çabucak güvendi !'^+%&/()=?_->£#${[]}\|;:><"); | |
Output: pijamali-hasta-yagiz-sofore-cabucak-guvendi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment