PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
potato
Forum Contributor
Posts: 192 Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree
Post
by potato » Tue Mar 14, 2006 9:32 pm
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
tmarion
Forum Newbie
Posts: 5 Joined: Sun Feb 26, 2006 3:23 am
Contact:
Post
by tmarion » Tue Mar 14, 2006 9:59 pm
Look at preg_replace or str_replace.
If you prefer regular expressions, use the first option otherwise use the second.
Thanks,
Tony
potato
Forum Contributor
Posts: 192 Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree
Post
by potato » Tue Mar 14, 2006 10:10 pm
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Mar 14, 2006 10:59 pm
you want to exclude commas?