Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Issue with url_title()
#1

[eluser]matthieujoly[/eluser]
Hello folks,

I have a very strange issue with the url_title() function of the url helper. The function works, but it sets the inital letter with lowercase.

I tried to use the last optional parameter of the function, but no luck. Nor TRUE, neither FALSE change the behavior.

Using the default function, the initial character should not be altered. Strange, strange, strange. Here is the code:

Code:
$data['Z']['Introduction'][0]['titre'] = 'Introduction';
$data['Z']['Introduction'][0]['url']   = base_url().'pdf/LeGuide/'.url_title($data['Z']['Introduction'][0]['titre']).'.pdf';

Here is the result:

http://www.achats-responsables.ch/pdf/LeGuide/introduction.pdf

If anyone has an idea, I would be more than grateful.

Have a good one folks!
#2

[eluser]Met[/eluser]
function url_title($str, $separator = 'dash', $lowercase = FALSE)

is the default

so simply

Code:
$foo=url_title($str,'dash');

will leave the case alone.

perhaps the problem is not with the url_title function?
#3

[eluser]matthieujoly[/eluser]
Thanks for the input. I tried it already and it doesn't change the behavior. Any other ideas?
#4

[eluser]danmontgomery[/eluser]
You have url_title() defined somewhere ignoring the 3rd parameter (extended url helper?), or there's more code you haven't posted.
#5

[eluser]matthieujoly[/eluser]
No url_title() function in the Controller, in the Model or in the View. The code from the 'system' folder is the following:

Code:
if ( ! function_exists('url_title'))
{
    function url_title($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));
    }
}

It doesn't look like it has been modified. I received this website and I am supposed to upgrade it.

Moreover, that's the autoload variable assignements that I have for helpers and models:

Code:
$autoload['helper'] = array('url','form','html');
$autoload['model'] = array();

Any other idea? It is indeed really strange.
#6

[eluser]danmontgomery[/eluser]
Look for an extended url helper in application/helpers
#7

[eluser]matthieujoly[/eluser]
Yes, I have something called My_url_helper.php and inside I get this piece of code that I think is problematic:

Code:
function url_title($title)
{
   return strtolower(remove_accents($title))
}

I removed the strtolower() function wrapper and it seams to work.

Thank you so much guys for all the really appreciated expertise and the help! The guy who gave me the code is really a sucker; it is hard coded, function are no so great. Well, you get the idea.

Anyway, thanks again a lot and have a great one. Week-end is approaching!




Theme © iAndrew 2016 - Forum software by © MyBB