Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Inflector::friendly_title question
  • If i have string with question mark like: "Would you like some tea?"
    friendly_title method with default settings returns "Would-you-like-some-tea?", maybe it should remove that question mark? Thanks.
  • Maybe extend friendly_title like so?:
    public static function friendly_title($str, $sep = '-', $lowercase = false)
     {
      // Allow underscore, otherwise default to dash
      $sep = $sep != '_' ? '-' : $sep;
    
      // Decode all entities to their simpler forms
      $str = html_entity_decode($str, ENT_QUOTES, 'UTF-8');
    
      $trans = array(
       '\s+' => $sep,   // one or more spaces => seperator
       $sep.'+' => $sep,  // multiple seperators => 1 seperator
       $sep.'$' => '',   // ending seperator => (nothing)
       '^'.$sep => '',   // starting seperator => (nothing)
       '\.+$' => '',   // ending dot => (nothing)
       '\?' => ''    // question mark
      );
      
      foreach ($trans as $key => $val)
      {
       $str = preg_replace("#".$key."#i", $val, $str);
      }
    
      // Only allow 7bit characters
      $str = static::ascii($str);
      
      // only allow chars and numbers
      $str = preg_replace("#[^a-z0-9\-\._]#i", '', $str);
    
      $str = \Security::strip_tags($str);
      
      if ($lowercase === true)
      {
       $str = \Str::lower($str);
      }
    
      return $str;
     }
    
  • Good spot, I've made this change in the develop branch.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion