BeBot - An Anarchy Online and Age Of Conan chat automaton
Development => Coding and development discussion => Topic started by: lazarus on November 01, 2007, 10: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:
<?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:
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:
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 :)
-
I do not understand the question.
-
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.
-
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.
-
I do not understand the question.
I want to put the input string
"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 :)
-
I found the solution that I can use.
<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 :) :
<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