I have a database containing a table named songs with a field title.
Now If my url is http://www.foo.com/songs/xxx
(xxx = the title of the song),
apache is silently redirecting to a page that looks similar to : /song.php?title=xxx
.
To embellish the URLs I convert spaces into underscores (cause I know some browser display %20 instead of space, not%20really%20user%20friendly%20ya%20know%20what%20i%20mean).
There's a snag cause if the title contains spaces and underscores (e.g. DJ_underscore fx
) and the script converts it into DJ_underscore_fx
the sql :
select * from songs where songs.title=xxx
can't find it.
here's the sketch to be more specific:
- a script fetches the different titles in the database
- converts all the space into underscore ( e.g.
name_of the song
->name_of_the_song
) - echo them as links ( e.g.
<a href="/songs/name_of_the_song">name_of_the_song</a>
) - the user clicks on the link and requests the document
- apache is silently redirecting ( e.g.
/songs/name_of_the_son
->/song.php?title=name_of_the_song
) - song.php fetches the specific data ( e.g.
select * from songs where songs.title=name_of_the_song
)
ok you see that there's no entry in the database that looks like name_of_the_song
but name_of the song
.
How can I manage the whole so that my URL remains clear and the title field is not restricted to a certain amount of values (can have spaces, underscore, dashes, well anything)?