Welcome Guest, Not a member yet? Register   Sign In
Cleaning up a database word for URL
#1

[eluser]Shinzo[/eluser]
Hi Guys!

I have a little question. I develop a community with mysql-databases. There I have an table with a field, which I use later as ID in my URLs.

i.e.: http://www.domain.de/page/show/my_word/

query is then: select * where clearword = my_word

I use this for clean urls.

So now i always have an simple function to clean up my word and destroy special characters and so on:

Code:
function name($alias) {
      $1 = Array("/ä/","/ö/","/ü/","/Ä/","/Ö/","/Ü/","/ß/");
      $2 = Array("ae","oe","ue","Ae","Oe","Ue","ss");
      
      $alias = preg_replace($1, $2, $alias);          
      $alias = strip_tags($alias);
      $alias = preg_replace('/&.+?;/', '', $alias);
      $alias = preg_replace('/[^\A-Za-z0-9 _-]/', '', $alias);
      $alias = preg_replace('/\s+/', '-', $alias);
      $alias = preg_replace('|-+|', '-', $alias);
      $alias = strtolower($alias);
      $alias = trim($alias, '-');
      
      return $alias;
}

I use CI not long and I wanted to ask if there is an Helper or a library which is doing the same thing. Maybe you have program an own function which you use with CI.


(Sorry for my bad english Wink )

Thanks for answers,
Shinzo
#2

[eluser]gon[/eluser]
You can use url_title function from the URL helper.
#3

[eluser]Shinzo[/eluser]
Thanks,

I think I will better use my posted function as CI-model. The standard helper is too simple for me. Sad




Theme © iAndrew 2016 - Forum software by © MyBB