L* R*
HOME FORUM DOWNLOADS
Content
  Links
     Browse SVN
     SVN Commit log
     Documentation (Wiki)
  Developers
     Taskmanager
User
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 01, 2008, 01:46:46 PM

Login with username, password and session length
Search



Advanced search
Support GoPHP5.org
BeBot - An Anarchy Online/Age Of Conan chat automaton > Forum > Development > Coding and development discussion > Topic: input message parser (regex)
Pages: [1]   Go Down
« previous next »
Print
Author Topic: input message parser (regex)  (Read 501 times)
0 Members and 1 Guest are viewing this topic.
lazarus
Rookie
**
Offline Offline

Posts: 25


input message parser (regex)
« on: November 01, 2007, 04:01:43 PM »

Hey all,

Im trying to make a regular expressions that can handle all the bot commands.
well maybe this is not needed but, how do I do it otherwise?

I got it to grab multiply items from one command.

the code look like this:
Code:
<?php

/**
 *
 *
 * @version $Id$
 * @copyright 2007
 */
$input = 'loot add <a href="itemref://206204/206204/1">Twilight\'s Murder</a> <a href="itemref://223322/206204/1">I am gimp</a> test';
preg_match_all('/<a href="([^"]*)">([^<]*)<\/a>/im', $input, $matches, PREG_SET_ORDER);
    
print_r($matches);
?>


and it result in this:
Code:
Array
(
    [0] => Array
        (
            [0] => <a href="itemref://206204/206204/1">Twilight's Murder</a>
            [1] => itemref://206204/206204/1
            [2] => Twilight's Murder
        )

    [1] => Array
        (
            [0] => <a href="itemref://223322/206204/1">I am gimp</a>
            [1] => itemref://223322/206204/1
            [2] => I am gimp
        )

)

but I still lack to be able to grab loot add and test

I tryed to put in (\w*) thro it give all kind of diffrent output.

The output im looking for is this:
Code:
Array
(
    [0] => Array
       (
            [0] => loot
       )
    [1] => Array
       (
            [0] => add
       )
    [2] => Array
       (
            [0] => <a href="itemref://206204/206204/1">Twilight's Murder</a>
            [1] => itemref://206204/206204/1
            [2] => Twilight's Murder
        )

    [3] => Array
        (
            [0] => <a href="itemref://223322/206204/1">I am gimp</a>
            [1] => itemref://223322/206204/1
            [2] => I am gimp
        )
    [4] => Array
       (
            [0] => test
       )
)

this parser should be working with all count of pre word/numbers and after word/numbers Smiley
« Last Edit: November 01, 2007, 04:04:09 PM by lazarus » Logged
Blueeagle
Omnipotent
BeBot Developer
Expert
********
Offline Offline

Gender: Male
Posts: 313



Re: input message parser (regex)
« Reply #1 on: November 01, 2007, 04:12:38 PM »

I do not understand the question.
Logged

The only problem that can't be solved by adding another wrapper is having too many wrappers.
Alreadythere
BeBot Maintainer
Administrator
Grandmaster
********
Offline Offline

Posts: 1085


Re: input message parser (regex)
« Reply #2 on: November 01, 2007, 05:16:02 PM »

The regular expression returns exactly what it's supposed to. Maybe you'll have to use more then one regular expression, or a more general one, or split up the input before preg_match(). I doubt that it's possible to match your wished output format exactly though.
Logged
lazarus
Rookie
**
Offline Offline

Posts: 25


Re: input message parser (regex)
« Reply #3 on: November 02, 2007, 04:15:18 AM »

Quote from: Alreadythere on November 01, 2007, 05:16:02 PM
The regular expression returns exactly what it's supposed to. Maybe you'll have to use more then one regular expression, or a more general one, or split up the input before preg_match(). I doubt that it's possible to match your wished output format exactly though.

ok how do I split it up?

I just want to be able to check against the words and items.

Logged
lazarus
Rookie
**
Offline Offline

Posts: 25


Re: input message parser (regex)
« Reply #4 on: November 02, 2007, 04:20:11 AM »

Quote from: Blueeagle on November 01, 2007, 04:12:38 PM
I do not understand the question.

I want to put the input string
Code:
"loot add <a href="itemref://206204/206204/1">Twilight\'s Murder</a> <a href="itemref://223322/206204/1">I am gimp</a> test"

into a array with each section in it.
as in

loot, add, first item, 2nd item, test.

So I can if ($output[4] == "test") echo "this is what I want";
and so on Smiley
Logged
lazarus
Rookie
**
Offline Offline

Posts: 25


Re: input message parser (regex)
« Reply #5 on: November 02, 2007, 11:01:29 AM »

I found the solution that I can use.

Code:
<pre>
<?php

/**
 *
 *
 * @version $Id$
 * @copyright 2007
 */

$str = 'Søg på <a href="http://www.google.com/">google</a> <a href="http://www.google.com/">google</a> for at finde det du mangler';
$chars = preg_split('/(<a.*<\/a>)/im', $str, -1, PREG_SPLIT_DELIM_CAPTURE);
print_r($chars);
?>

</pre>

that give this result Smiley :
Code:
<pre>
Array
(
    [0] => Søg på
    [1] => <a href="http://www.google.com/">google</a> <a href="http://www.google.com/">google</a>
    [2] =>  for at finde det du mangler
)
</pre>

from this I know that chars[0] is all before the items, chars[1] is all items posted and chars[2] is everything after items
Logged
Pages: [1]   Go Up
Print
BeBot - An Anarchy Online/Age Of Conan chat automaton > Forum > Development > Coding and development discussion > Topic: input message parser (regex)
« previous next »
 
Jump to:  

Recent
[request] Raid timers
by Alreadythere
[Today at 11:42:32 AM]

Shared DB online list
by Temar
[Today at 01:55:47 AM]

relay colors
by Temar
[Today at 01:54:56 AM]

BeBot v0.6.0 released
by Alreadythere
[November 30, 2008, 05:32:00 PM]

Change to Bid.php
by Temar
[November 30, 2008, 11:41:44 AM]

OnlineOrg
by Jiheld
[November 29, 2008, 12:44:27 PM]

Silly Newbie Question.
by Temar
[November 29, 2008, 12:00:02 PM]

massive_pvp_time_table 1
by gerborg
[November 29, 2008, 06:55:35 AM]

Bot not see Guild Chat
by Delvar
[November 28, 2008, 08:30:34 AM]

Starting Bot
by Allisande
[November 28, 2008, 07:08:21 AM]
Stats
Members
Total Members: 1243
Latest: Whackoeng
Stats
Total Posts: 11143
Total Topics: 1505
Online Today: 21
Online Ever: 168
(July 01, 2007, 09:30:02 PM)
Users Online
Users: 0
Guests: 13
Total: 13

Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC
TinyPortal v0.9.8 © Bloc | NewDef design by Bloc
Page created in 0.79 seconds with 28 queries. (Pretty URLs adds 0.026s, 4q)
Loading...