Jump to content

Sarching a string, not strstr??


AbydosGater

Recommended Posts

Hey, Ive been working on a chat script for my website, its going great, but my members have been asking me to add a similies set to chat!
And i said yeah it would be easy..
All i have to do is check if the string contains one of the keywords, (ie : P) and then if it does use str_replace?, as far as i know thats correct!

But how would i search if my string contains the keyword?
I was going to use strstr, but on reading the manual i relised that this only...

"Returns part of haystack string from the first occurrence of needle to the end of haystack. "

What should i use?

Thanks Abydos
Link to comment
Share on other sites

Hi, back again! i tryed this, and no success!

I made a function...

[code]
function modifyPost($message){
$message = $message;
$message = str_replace("\n", "<br />", $message);
$message = str_replace("fuck", "----", $message);
return $message ;
};
[/code]

and it is run just before the post is submitted to the database...

[code]
if($message){
modifyPost($message);
mysql_query("INSERT INTO chat_messages (message_id, member_id, handle, ip, timestamp, message, type) VALUES (NULL , '0', '$handle', '$ip', CURRENT_TIMESTAMP , '$message', 'post') ") or die(mysql_error()); 
};

[/code]

It should replace the "f" word with ----, but it doesnt, it runs ok and the message is added to the database, but it doesnt add a <br> for every newline in the message and it doesnt censor the word!

Why is it not working??

Thanks abydos
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.