Jump to content

Recommended Posts

Mmmk, i'm working on a IRC Bot and this never occured to me on how to do it but my current bot is "disrupting" users when they have the selected word in the actual word they type.. I have my bot detect hi or hello right if someone types "this" anywhere in the sentance it makes the bot respond. Well I thought of a few ways but they would have a slim chance of working and decided i'd ask you guys.

 

Right now it detects a whole string *Not array* and searches for the key letters in the word and I need it to parse it so it doesn't respond if its not the word by its self..

 

Ideas?

Link to comment
https://forums.phpfreaks.com/topic/169277-solved-parsing-words/
Share on other sites

Umm I guess I forgot to mention the original comparison is using eregi and I just need it to detect hi or hello as a word and not in a word. Just detect hi or hello as its OWN word and nothing else..

 

Looked at what you said and the description didn't seem to do anywhere close to what I wanted.

Link to comment
https://forums.phpfreaks.com/topic/169277-solved-parsing-words/#findComment-893261
Share on other sites

eregi is regex. if you want to detect just the word hi or hello something like

 

$patternHi = "/^hi$/";
$patternHello = "/^hello$/";

 

should work (hopefully. haven't done much regex at all, but have done some with javascript, and I don't know how much different, or if there is a difference, between javascript regex and php regex)

 

that will match the word only.

 

now that i think of it, just having the word as the pattern would probably work too. In any case, for regex help, i'm not the one to go to.

 

Hope that helps!

Link to comment
https://forums.phpfreaks.com/topic/169277-solved-parsing-words/#findComment-893264
Share on other sites

You need to use the word boundry keyword: \b

 

I couldn't get it to work with eregi, but I could with preg_match().

 

$userText = "Hi there"; //Would return true in the test below
$userText = "Hit this"; //Would NOT return true in the test below


$botSearch = '/\bhi\b/i'; //Added i at the end to make case insensitive

if(preg_match($botSearch, $userText)!==0)
{
    echo "Found the WORD 'hi'";
}

Link to comment
https://forums.phpfreaks.com/topic/169277-solved-parsing-words/#findComment-893269
Share on other sites

You need to use the word boundry keyword: \b

I couldn't get it to work with eregi, but I could with preg_match().

 

$userText = "Hi there"; //Would return true in the test below
$userText = "Hit this"; //Would NOT return true in the test below


$botSearch = '/\bhi\b/i'; //Added i at the end to make case insensitive

if(preg_match($botSearch, $userText)!==0)
{
    echo "Found the WORD 'hi'";
}

 

Ahh! Good ol' reliable preg_match :D!

 

Alright i'll give it a go and see what I get.

Link to comment
https://forums.phpfreaks.com/topic/169277-solved-parsing-words/#findComment-893277
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.