![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
King of Portal
|
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?
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis |
|
|
|
|
|
#2 |
|
King of Portal
|
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 -_-
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis |
|
|
|
|
|
#3 |
|
King of Portal
|
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]
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Stuck with a C problem | Polaris | C++ | 8 | Aug 19th, 2006 3:30 PM |
| output - 842150451? | programmingnoob | C++ | 3 | Apr 23rd, 2006 8:23 PM |
| writing a scanner (lexical analysis) | programmingnoob | C++ | 6 | Mar 19th, 2006 4:12 PM |
| cgi/perl script + IE problem | joyceshee | Perl | 2 | Jan 24th, 2006 11:10 AM |
| Pointers! Why? | LOI Kratong | C++ | 33 | Dec 17th, 2005 11:33 PM |