Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
See more:
When I Post any question in codeproject, it generates the URL of that question replacing the spaces with "-" sign.
For Example If I post a question with such kind of title
How Can I Rewrite URL

When I will submit this question, it will generate a URL of similar this
http://www.codeproject.com/Questions/314951/How-Can-I-Rewrite-URL


Means it will replace the white spaces of the title with "-" signs.

How can I do that with my URLs. I have used str_replace function to replace the white spaces with "-". And for using this title replace back the "-" with white spaces.
But the Problem is, There may be some title that itself contains "-" sign, then how I will handle that?

Please guide me about this Problem.
Posted
Comments
Sergey Alexandrovich Kryukov 16-Jan-12 14:17pm    
Why?
--SA

1 solution

I think you are asking about something which is normally solved using the techniques and encoding format called URL encoding.

This is explained here: http://en.wikipedia.org/wiki/URL_encoding[^].

When it comes to PHP, please see:
http://php.net/manual/en/function.urlencode.php[^],
http://php.net/manual/en/function.urldecode.php[^].

—SA
 
Share this answer
 
Comments
rashidfarooq 16-Jan-12 14:45pm    
But urlencode function replaces the spaces with plus (+) sign and I want the white spaces to be replaced with minus (-) sign.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900