Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 1st, 2006, 1:31 AM   #1
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 431
Rep Power: 4 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
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
grimpirate is offline   Reply With Quote
Old Dec 1st, 2006, 3:42 AM   #2
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 431
Rep Power: 4 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
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
grimpirate is offline   Reply With Quote
Old Dec 1st, 2006, 4:07 AM   #3
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 431
Rep Power: 4 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
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
grimpirate is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:36 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC