Page 1 of 1

change characters for url?

Posted: Tue Mar 14, 2006 9:32 pm
by potato
Hi everybody,

long time no see... :)

i came on the problem that when my artists sign up, i want to give them a url like:
http://www.mysite.com/bands/artistname

For that, no problem.
But... When the artistname is for example:
http://www.mysite.com/bands/more words artistname

I would like that all the spaces in the artistname are replaced with underscores, and that
characters that arent valid in a url are deleted.
Whit what function i can do that?

Any help would be great...

Greets,
Tom

Posted: Tue Mar 14, 2006 9:59 pm
by tmarion
Look at preg_replace or str_replace.

If you prefer regular expressions, use the first option otherwise use the second.

Thanks,
Tony

Posted: Tue Mar 14, 2006 10:10 pm
by potato
Ok, i found it!

here it is:

Code: Select all

$string = "here comes the string...";
$string = ereg_replace("[^A-Z, a-z,&]", "", $string);
$string = ereg_replace("[^A-Z,a-z,&]", "_", $string);
echo $string;

//will output: here_comes_the_string

Posted: Tue Mar 14, 2006 10:59 pm
by feyd
you want to exclude commas?