Make URL function

Permalink 1 user found helpful
I am wandering if there is a function that will allow me to take a string and make it a url friendly link.

I can do come string replacing on it but no that the Page Alias must go through some conversion and wandered if there is helper function to do this?

I've checked in the text helper but can't see anything that may do this does concrete5 have a function for this?

TheRealSean
 
mkly replied on at Permalink Reply
mkly
From what I can tell its
function makeAlias(value, formInputID)
in
concrete/elements/collection_add.php
Unfortunately, it's a javascript function not php.
TheRealSean replied on at Permalink Reply
TheRealSean
I have added a function to my text helper to do it for anyone else wanting to do something similar
/*Ripped Off the Javascrip function to do the Same thing as the makeAlias() */
   public function makeAlias($alias) {
      $alias = preg_replace("/[&]/i", "and",$alias);
      $alias = preg_replace("/[\s|.]+/i", "-",$alias);
      //needed for preventing numbers at the begining of class, but not needed for urls
$alias = preg_replace('/[^[:alnum:]]/', '', $alias);
      //had trouble replacing the code by fernandos €Š,š,Žƒé
//so left that bit out as its not for me
      $alias = trim($alias,"/");
      $alias = strtolower($alias);
      return $alias;
}


A few of these could be a str_replace rather then preg_replace I believe server wise str_replace comes out quicker but for consistancy (I was copy pasting then tweaking)
mkly replied on at Permalink Best Answer Reply
mkly
Awesome. I added fernandos back in.
/*Ripped Off the Javascrip function to do the Same thing as the makeAlias() */
public function makeAlias($alias) {
      $alias = preg_replace("/[&]/i", "and",$alias);
      $alias = preg_replace("/[\s|.]+/i", "-",$alias);
      //needed for preventing numbers at the begining of class, but not needed for urls - added "\-":mkly
         $alias = preg_replace('/[^\-[:alnum:]]/u', '', $alias);
         //thanks again fernandos
            $alias = preg_replace('/[\x{00C4}\x{00E4}]/ui', "ae", $alias);
            $alias = preg_replace('/[\x{00D6}\x{00F6}]/ui', "oe", $alias);
            $alias = preg_replace('/[\x{00DF}]/ui', "ss", $alias);
            $alias = preg_replace('/[\x{00DC}\x{00FC}]/ui', "ue", $alias);
            $alias = preg_replace('/[\x{00C6}\x{00E6}]/ui', "ae", $alias);
            $alias = preg_replace('/[\x{00D8}\x{00F8}]/ui', "oe", $alias);
            $alias = preg_replace('/[\x{00C5}\x{00E5}]/ui', "aa", $alias);
            $alias = preg_replace('/[\x{00E8}\x{00C8}\x{00E9}\x{00C9}]/ui', "e", $alias);
TheRealSean replied on at Permalink Reply
TheRealSean
That's great work, no wonder I could not get the extra bits, thanks for sharing
Mnkras replied on at Permalink Reply
Mnkras
in the text helper, there is something like sanatizeFilePath that does the same thing
mkly replied on at Permalink Reply
mkly
orly?
Mnkras replied on at Permalink Reply
Mnkras
TheRealSean replied on at Permalink Reply
TheRealSean
But doesn't that last line, convert dashes to slashes?

$handle = str_replace('-', PAGE_PATH_SEPARATOR, $handle);
TheRealSean replied on at Permalink Reply
TheRealSean
oop never mind I seem to get my constants mixed up the PAGE_PATH_SEPARATOR is a dash I assume this is to make sure it gets rid of any long or short dashes?

I think that's why I never used it when I first looked at it thinking it would add slashes.
Mnkras replied on at Permalink Reply
Mnkras
The page path separator used to be _ now it is - its for if you want it back at _
TheRealSean replied on at Permalink Reply
TheRealSean
No "-" is a great idea, we where having this very discussion at work as to the difference between using the _ and - and Matt Cutts settled it for us

http://www.youtube.com/watch?v=AQcSFsQyct8...