Jump to content

Putting "-" instead of "%20"


Sangha-08

Recommended Posts

Hi guys,

 

I'm just having a little trouble with my new script.

 

<?php $_GET print['v']; ?>

 

so, when i go to my website and write on the url http://www.mywebsite.com/play.php?v=Name of the video

 

but its gets "encrypted" to http://www.mywebsite.com/play.php?name%20of%20the%20video

and that kinda messes up all my urls, and is really bad for SEO

 

is there a way to change the "%20" to "-" so that the url looks something like

 

http://www.mywebsite.com/play.php?v=Name-of-the-video

 

Thanks for all you help, much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/127951-putting-instead-of-20/
Share on other sites

The %20 is just the standard encoding for spaces in URLs. I use a preg_replace to change any non-alphanumeric characters when I insert to the database to generate a slug:

 

$slug = preg_replace('/[^a-z0-9]/i', '-', $name);

 

You only want to strip one thing, though, so you could try an str_replace instead: http://uk.php.net/str_replace

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.