Strip words from form PHP

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
matu
Forum Newbie
Posts: 2
Joined: Tue Nov 30, 2010 8:23 pm

Strip words from form PHP

Post by matu »

Hi Guys

Just wondering if anyone here can help me out
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.

Code: Select all

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.
Thanks in advance an help is welcomed.
Mat
matu
Forum Newbie
Posts: 2
Joined: Tue Nov 30, 2010 8:23 pm

Re: Strip words from form PHP

Post by matu »

Im not that great at php but I think it is something like this that is needed

Code: Select all

if (strpos($content = 'hating') !== false); {
		$content = preg_replace('hating', '', $content, 1);
		}
Post Reply