// Stress $test = "Mess'd up --text-- just (to) stress /test/ ?our! `little` \\clean\\ url fun.ction!?-->"; // return : mess'd-up-text-just-(to)-stress-/test/-our!-`little`-\clean\-url-fun.ction!-> // #WRONG // Italian $test = "ti diamo il benvenuto all'Hotel&Restaurant; dove la cortesia è di casa"; // return : ti-diamo-il-benvenuto-all'hotel&restaurant;-dove-la-cortesia-e-di-casa // #WRONG // French $test = "Peux-tu m'aider s'il te plaît?"; // return : peux-tu-m'aider-s'il-te-plait // #WRONG // Swedish $test = "Tänk efter nu – förr'n vi föser dig bort"; // return : tank-efter-nu--frr'n-vi-fser-dig-bort // #WRONG echo \Inflector::friendly_title($test, $sep = '-', $lowercase = true);in friendly title there are bad url characters ...
I have problems with $lowercase parameter using your code :Calvin Froedge wrote on Friday 17th of June 2011:Hey David, I had written a similar piece of code to format directory names for storing uploaded files. I didn't realize friendly_title() existed. I'm going to start using this method along with your updated code. I'll let you know if I run into any problems. One question...in the regular expression you used... /[^a-zA-Z0-9\/_|+ -]/ I know that ^a-zA-Z0-9 matches lowercase & uppercase a-z, and 09, and that \ escapes / so you can match / and _. I read that | means match on either side. What does "|+ -" accomplish? The function I was using was much simpler: preg_replace('#[^a-z0-9]#', $sep, strtolower($name))
preg_replace('#[^a-z0-9]#', $sep, strtolower($name))
$test = "<b>Fuel</b> is a community driven PHP 5 web framework"; echo \Inflector::friendly_title($test, $sep = '-', $lowercase = false) . '<br/>';
if($lowercase)
return preg_replace('#[^a-z0-9]#', $sep, $name); return preg_replace('#[^a-z0-9]#', $sep, strtolower($name));
$str = preg_replace("#[^a-z0-9]#i", $sep, $str);
It looks like you're new here. If you want to get involved, click one of these buttons!