Cutting "The" off the beginning of a string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
VKX
Forum Commoner
Posts: 41
Joined: Mon Oct 03, 2005 1:43 pm

Cutting "The" off the beginning of a string

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Code: Select all

$name1 = preg_replace('/^The /', '', $name);
(#10850)
VKX
Forum Commoner
Posts: 41
Joined: Mon Oct 03, 2005 1:43 pm

Post by VKX »

Works perfectly, thank you so much!
Post Reply