Question

I am using that function in order to prevent wrong URL structure:

    <?
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));
    }
}

Input string:

ATA'DAN MEZİTLİDE 4+1 HAVUZLU GÜVENLİKLİ KAÇMAZ!!!

Output:

ATADAN-MEZITLIDE-41-HAVUZLU-GUVENLIKLI-KACMAZ

What I want:

ATADAN-MEZITLIDE-4+1-HAVUZLU-GUVENLIKLI-KACMAZ
Was it helpful?

Solution

Replace this part of your code and check it:-

'[^a-z0-9\-\+\._]'        => '',

What it does is allow the plus(+) sign. And not replace it with ''.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top