Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP Inflector slug issue

When I use:

Inflector::slug("My Lovely & long slug");

On my local server I get:

My_Lovely_long_slug

When I use it on my server I get:

Lo_l_lo_lu

What gives? This issue is also affecting all my cache names which I assume are using the Inflector class. Any help appreciated.

like image 283
woodscreative Avatar asked Jul 15 '26 05:07

woodscreative


2 Answers

looks like to different versions of cake? ive seen this reported before but dont have any references for you. Tested on my server for ~ 1.3.6/7 and it works as expected.

if the versions of cake are the same try and do a 'git bisect' which will give you an answer pretty quick

update:

seems to do with your PCRE libraries installed on the server that are older etc. give them an update and all should be fine

like image 117
dogmatic69 Avatar answered Jul 17 '26 23:07

dogmatic69


So I made my own slug for now.

function permalink ($string = '',$length = false)
{
    $string = strtolower($string); // All lowercase
    $string = preg_replace('/[^%a-z0-9]/',' ', $string); // Remove garbage
    $string = preg_replace('/\s+/','_', $string);
    $string = preg_replace('|-+|','_', $string);
    if ($length) $string = substr($string,0,$length); // Limit string length?
    $parsed = trim($string,'_'); // Trim pre and post trailing delims
    return $parsed;
}
like image 21
woodscreative Avatar answered Jul 18 '26 00:07

woodscreative