Strip first word from a string

I basically have a script that lets users post comments but I have it setup so that at the begin of every comment the user put in the script puts in hate automactically which is how I want it to work, but sometimes the user put in hating themselves and it comes out with hating hating and then users comment. Anyone have any ideas on how I can get it to strip out hating or hates if it is the first word in the sentence inputted by the user? At the moment I have it set to remove hating but it removes it where ever it is used in the sentence which is not good at the moment. Here is some of the code that is being used.

if (strpos($content, 'hating') !== false) {
  $content = str_replace("hating", "", $content);
  }

  $query="INSERT INTO posts SET story='hating ".mysql_real_escape_string($content)."', time_added='".time()."', date_added='".date("Y-m-d")."', active='$active', pip='".$_SERVER['REMOTE_ADDR']."'"; 
  $result=$conn->execute($query);
  $pid = mysql_insert_id();

SET story='hating " is where I have set it to put in the word hating and include it in the database when submitted.

Answers


Try:

$content = preg_replace("(^hating )","",$content);

Need Your Help

iOS - Storyboard - Delegate for pop over

ios uipopovercontroller storyboard

I'm using storyboard in my ipad application and successfully able to do transitions, use segues etc.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.