Page 1 of 1

Cutting "The" off the beginning of a string

Posted: Tue May 23, 2006 12:40 am
by VKX
I have a database of movie titles. I want to cut "The" off the beginning, so that a movie like "The Lost Boys" would become "Lost Boys". I do it like this:

Code: Select all

$name1 = ltrim($name, "The ");
However, I noticed that trims the beginning of some titles. For instanct, "Team America" becomes "eam America." How can I make sure I only remove "The " and not a word that begins with T?

Posted: Tue May 23, 2006 12:49 am
by Christopher

Code: Select all

$name1 = preg_replace('/^The /', '', $name);

Posted: Tue May 23, 2006 12:57 am
by VKX
Works perfectly, thank you so much!