![]() |
Token Problem... sorta
I've created a function called parsePost() here it is:[PHP]function parsePost($input){
$modify = $input; $tokens = array(); while(false !== $openLocate = strpos($modify, chr(60))){ if(count($tokens) == 0){ array_push($tokens, substr($modify, 0, $openLocate)); } else { array_push($tokens, chr(60) . substr($modify, 0, $openLocate)); if(false !== $closeLocate = strpos($tokens[count($tokens) - 1], chr(62))){ $temp = array_pop($tokens); array_push($tokens, substr($temp, 0, $closeLocate + 1)); array_push($tokens, substr($temp, $closeLocate + 1)); } } $modify = substr($modify, $openLocate + 1); } if(count($tokens) == 0){ array_push($tokens, $modify); } else { array_push($tokens, chr(60) . $modify); if(false !== $closeLocate = strpos($tokens[count($tokens) - 1], chr(62))){ $temp = array_pop($tokens); array_push($tokens, substr($temp, 0, $closeLocate + 1)); array_push($tokens, substr($temp, $closeLocate + 1)); } } $temp = array(); for($i = 0; $i < count($tokens); $i++){ if(strlen($tokens[$i]) != 0){ array_push($temp, $tokens[$i]); } } $tokens = $temp; for($i = 0; $i < count($tokens); $i++){ $openLocate = strpos($tokens[$i], chr(60)); $closeLocate = strpos($tokens[$i], chr(62)); if($openLocate === 0 && $closeLocate === strlen($tokens[$i]) - 1){ } else { $tokens[$i] == htmlentities($tokens[$i]); } } return $tokens; }[/PHP]It returns then input tokenized in the manner that I want, the problem is that for some reason it won't do the conversion of htmlentities as specified, can anyone tell me what's amiss here? |
Never mind I figured it out: the error was here
$tokens[$i] == htmlentities($tokens[$i]); I'm using a comparison operator rather than an assignment operator -_- |
Take THIS BBCode!
[PHP]function parsePost($input){ $illegalTags = array('applet', 'base', 'basefont', 'body', 'embed', 'frame', 'frameset', 'head', 'html', 'iframe', 'ilayer', 'layer', 'link', 'meta', 'object', 'param', 'script', 'style', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'title', 'tr', '/applet', '/base', '/basefont', '/body', '/embed', '/frame', '/frameset', '/head', '/html', '/iframe', '/ilayer', '/layer', '/link', '/meta', '/object', '/param', '/script', '/style', '/table', '/tbody', '/td', '/tfoot', '/th', '/thead', '/title', '/tr'); $illegalOthers = array('onabort=', 'onactivate=', 'onafterprint=', 'onafterupdate=', 'onbeforecopy=', 'onbeforecut=', 'onbeforedeactivate=', 'onbeforeeditfocus=', 'onbeforepaste=', 'onbeforeprint=', 'onbeforeunload=', 'onbeforeupdate=', 'onblur=', 'onbounce=', 'oncellchange=', 'onchange=', 'onclick=', 'onclose=', 'oncontextmenu=', 'oncontrolselect=', 'oncopy=', 'oncut=', 'ondataavailable=', 'ondatasetchanged=', 'ondatasetcomplete=', 'ondblclick=', 'ondeactivate=', 'ondrag=', 'ondragdrop=', 'ondragend=', 'ondragenter=', 'ondragleave=', 'ondragover=', 'ondragstart=', 'ondrop=', 'onerror=', 'onerrorupdate=', 'onfilterchange=', 'onfinish=', 'onfocus=', 'onhelp=', 'onkeydown=', 'onkeypress=', 'onkeyup=', 'onload=', 'onlosecapture=', 'onmousedown=', 'onmouseenter=', 'onmouseleave=', 'onmousemove=', 'onmouseout=', 'onmouseover=', 'onmouseup=', 'onmove=', 'onpaste=', 'onpropertychange=', 'onreadystatechange=', 'onreset=', 'onresize=', 'onresizeend=', 'onresizestart=', 'onrowenter=', 'onrowexit=', 'onrowsdelete=', 'onrowsinserted=', 'onscroll=', 'onselect=', 'onselectionchange=', 'onselectstart=', 'onstart=', 'onstop=', 'onsubmit=', 'onunload=', chr(40), '&#', 'javascript'); $nonTagCount = 0; $modify = str_replace(chr(30), ' ', $input); $tokens = array(); while(false !== $openLocate = strpos($modify, chr(60))){ if(count($tokens) == 0){ array_push($tokens, substr($modify, 0, $openLocate)); } else { array_push($tokens, chr(60) . substr($modify, 0, $openLocate)); if(false !== $closeLocate = strpos($tokens[count($tokens) - 1], chr(62))){ $temp = array_pop($tokens); array_push($tokens, substr($temp, 0, $closeLocate + 1)); array_push($tokens, substr($temp, $closeLocate + 1)); } } $modify = substr($modify, $openLocate + 1); } if(count($tokens) == 0){ array_push($tokens, $modify); } else { array_push($tokens, chr(60) . $modify); if(false !== $closeLocate = strpos($tokens[count($tokens) - 1], chr(62))){ $temp = array_pop($tokens); array_push($tokens, substr($temp, 0, $closeLocate + 1)); array_push($tokens, substr($temp, $closeLocate + 1)); } } $temp = array(); for($i = 0; $i < count($tokens); $i++){ if(strlen($tokens[$i]) != 0){ array_push($temp, $tokens[$i]); } } $tokens = $temp; for($i = 0; $i < count($tokens); $i++){ $openLocate = strpos($tokens[$i], chr(60)); $closeLocate = strpos($tokens[$i], chr(62)); if($openLocate === 0 && $closeLocate === strlen($tokens[$i]) - 1){ $temp = substr($tokens[$i], 1); for($j = 0; $j < 33; $j++){ $temp = str_replace(chr($j), '', $temp); } $temp = str_replace(chr(127), '', $temp); $temp = strtolower($temp); for($j = 0; $j < count($illegalTags); $j++){ if(strpos($temp, $illegalTags[$j]) === 0){ $tokens[$i] = htmlentities($tokens[$i]); } } for($j = 0; $j < count($illegalOthers); $j++){ if(strpos($temp, $illegalOthers[$j]) !== false){ $tokens[$i] = htmlentities($tokens[$i]); } } } else { $tokens[$i] = htmlentities($tokens[$i]); $nonTagCount++; } } $temp = ''; for($i = 0; $i < count($tokens); $i++){ $temp .= $tokens[$i]; } $temp = str_replace(chr(13) . chr(10), '<br />', stripslashes($temp)); $modify = $temp; for($j = 0; $j < 33; $j++){ $temp = str_replace(chr($j), '', $temp); } $temp = str_replace(chr(127), '', $temp); $temp = strtolower($temp); if($nonTagCount > 0 && strlen($temp) > 0){ return $modify; } else { return $modify .= 'EMPTY ENTRY'; } }[/PHP] |
| All times are GMT -5. The time now is 1:18 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC