using preg_replace to correct a title
i have written a script that allows me to track my DVD collection. I type in the title and some other info and it all gets stored in a MySQL database on my webserver. Everything is written in PHP4. I have a problem with alphabetization when i pull out the results, because many titles start with A, AN, or THE. I am trying to use preg_replace to detect if the title string starts with one of these three (followed by a space) and if so, strip it off the front and append it to the end with a comma and space. I plan to modify the title string before i insert the info into my database. I know there is an easy way to do this whole thing in one statement, but i cannot seem to get it figured out. Here is some info:
if i start with the following:
$MovieTitle = "The Matrix"
$MovieTitle = preg_replace(SOMETHING HERE);
i want to end with the following:
$MovieTitle == "Matrix, The"
(same thing for "An " or "A ")
Any help will be greatly appreciated.
THANKS!
Last edited by techtheatre : 01-16-2007 at 02:23 PM.
|