間違ったURL構造を防ぐために、この関数を使用しています。
<?
if (!defined('BASEPATH'))
exit('No direct script access allowed');
if (!function_exists('seo_helper')) {
function seo_link($deger) {
$turkce=array("ş","Ş","ı","(",")","'","ü","Ü","ö","Ö","ç","Ç"," ","/","*","?","ş","Ş","ı","ğ","Ğ","İ","ö","Ö","Ç","ç","ü","Ü");
$duzgun=array("s","S","i","","","","u","U","o","O","c","C","-","-","-","","s","S","i","g","G","I","o","O","C","c","u","U");
$deger=str_replace($turkce,$duzgun,$deger);
$deger = url_title_plus($deger);
return $deger;
}
}
if ( ! function_exists('url_title_plus'))
{
function url_title_plus($str, $separator = 'dash', $lowercase = FALSE)
{
if ($separator == 'dash')
{
$search = '_';
$replace = '-';
}
else
{
$search = '-';
$replace = '_';
}
$trans = array(
'&\#\d+?;' => '',
'&\S+?;' => '',
'\s+' => $replace,
'[^a-z0-9\-\._]' => '',
$replace => $replace,
$replace.'$' => $replace,
'^'.$replace => $replace,
'\.+$' => ''
);
$str = strip_tags($str);
foreach ($trans as $key => $val)
{
$str = preg_replace("#".$key."#i", $val, $str);
}
if ($lowercase === TRUE)
{
$str = strtolower($str);
}
return trim(stripslashes($str));
}
}
入力文字列:
ATA'DAN MEZİTLİDE 4+1 HAVUZLU GÜVENLİKLİ KAÇMAZ!!!
出力:
ATADAN-MEZITLIDE-41-HAVUZLU-GUVENLIKLI-KACMAZ
私が欲しいもの:
ATADAN-MEZITLIDE-4+1-HAVUZLU-GUVENLIKLI-KACMAZ