Jump to content

How to look for a word in a string


ILYAS415

Recommended Posts

Okay i'm making a chat room thing and i would like to know how check if the user has entered a certain word into his her string.

 

Basically im trying to make a /me commad (the typical action command).

 

I have already tried using this....

 

strpos("/me", $string, 1);

 

however that means that the user can enter in....

 

wow the /me command is wicked

 

and if will be seen as an action command because it got /me inside it.

I only want the script to look for /me if it is in the beggining of a sentance.

Link to comment
Share on other sites

Nope not working... :S

 

heres my code im using...

 

 

	if (strpos($msg, "/me") === "0"){
	$msg= str_replace("/me", "", $msg);
	$out="$chattext ".ucfirst($fetch->username)." <font color=white>$msg</font><br>";
	}else{
	$out = $chattext . $n . " - " . $msg . "<br>";
	$out = str_replace("\'", "'", $out);
	$out = str_replace("\\\"", "\"", $out);
	}
	$out= chat($out);

 

Thanks again

Link to comment
Share on other sites

Don't have $fetch object so I changed $fetch->username to $username.

Also don't have you chat() function, but

 

<?php
        $username = 'xyz';
        $msg = '/me foo bar';
        $chattext = 'abc';
         
        if (strpos($msg, "/me") === 0){
	    $msg= str_replace("/me", "", $msg);
	    $out="$chattext ".ucfirst($username)." <font color=white>$msg</font><br>";
	}else{
	    $out = $chattext . $n . " - " . $msg . "<br>";
	    $out = str_replace("\'", "'", $out);
	    $out = str_replace("\\\"", "\"", $out);
	}
	echo $out;                      // --> abc Xyz <font color=white> foo bar</font><br>
?>

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.