Dubz
04-22-2012, 07:34 AM
When this function I have is run, it removes any + signs for some reason. I looked for where it's doing it and can't seem to find it (even used ctrl+f). If someone can help me figure out why this is happening, that would be great.
//$p example = '<m t="2+2" u="123" i="0" />'
//m = packet type
//t = text
//u = user id
//i = unknown still
function parse($p, $handle = true)
{
global $bot;
if(substr_count($p, '>') > 1)
$p = explode('/>', $p);
foreach((Array)$p as $p2)
{
$p2 = trim($p2);
if($bot->debug)
echo "->>\t $p2\n";
if(strlen($p2) < 5) return;
$type = trim(strtolower(substr($p2, 1, strpos($p2.' ', ' '))));//packet type
$p2 = trim(str_replace("<$type",'', str_replace('/>', '', $p2)));//remove details so it is just the info to be parsed
parse_str(str_replace('"', '', str_replace('" ', '&', str_replace('="', '=', str_replace('&', '__38', $p2)))), $this->packet[$type]);
foreach($this->packet[$type] as $k => $v)
{
$this->packet[$type][$k] = str_replace('__38', '&', $v); //htmlspecial chars are protected instead of being parsed
}
if($handle)
$this->handle($type, $this->packet[$type]);
}
}
Also, if your wondering, this is for my chat bot (I've asked other questions for it here).
//$p example = '<m t="2+2" u="123" i="0" />'
//m = packet type
//t = text
//u = user id
//i = unknown still
function parse($p, $handle = true)
{
global $bot;
if(substr_count($p, '>') > 1)
$p = explode('/>', $p);
foreach((Array)$p as $p2)
{
$p2 = trim($p2);
if($bot->debug)
echo "->>\t $p2\n";
if(strlen($p2) < 5) return;
$type = trim(strtolower(substr($p2, 1, strpos($p2.' ', ' '))));//packet type
$p2 = trim(str_replace("<$type",'', str_replace('/>', '', $p2)));//remove details so it is just the info to be parsed
parse_str(str_replace('"', '', str_replace('" ', '&', str_replace('="', '=', str_replace('&', '__38', $p2)))), $this->packet[$type]);
foreach($this->packet[$type] as $k => $v)
{
$this->packet[$type][$k] = str_replace('__38', '&', $v); //htmlspecial chars are protected instead of being parsed
}
if($handle)
$this->handle($type, $this->packet[$type]);
}
}
Also, if your wondering, this is for my chat bot (I've asked other questions for it here).