Hi...So I have this program which sort of deliminates a string (a big ass string) breaking it up into sections.
I had another thread asking how to do this, but in the end just ended up writing my own code...is it the best way? probably not...but it works for the most part.
So what the code does is it goes thru a string (currently i put it into a textarea and then i retrieve it with $_POST...) http://pdem.mattwatson.info/Standards/standard.txt and it looks like that.
So as you see, some lines have @ in front, some #,,+,|. These signify which column of my database they should belong in (i do this in MS word, change the numbering style to @1 instead of just 1, so that the database has a way to differentiate them)....So for example the @ belong in the field 'tier1', # in 'tier2'...and so on.
Like I said, it works great 355/374 (yes that is the exact amount 😛)...it just, those 19 times it doesnt work, seems to not enter the row into the databse. an example are the last 4 rows...it does get that far (the while loop does) but it doesnt add them to the database...there are also a bunch of other rows randomly thru out that just never get inputed (i am at TreeViewID 3500+, so you can tell that I have tested it a lot of times)...
I was just wondering if someone may know why it is looking over certain rows (the SAME rows every time)...and there is nothing wrong with them, i thought "oh maybe it is missing a #" ... but its not, it looks 100% fine. and btw, it isnt JUST the # that get skipped, there are a couple of each type of symbol
Here is my code: (like I said there is probably a better way, but it gets the job done 😛) and notice, there is a lot of repetition, so you dont have to read it ALL 😃
Basically what it does is it goes thru the string and creates words letter by letter. if it hits one of the symbols, it knows that the word is complete, then adds that word to its array. then it starts again and goes until it hits the next symbol.
it knows which array to put the word in based on which symbol is inFRONT of the word 🙂
//GLOBAL VARIABLES//
$t0 = array();//parts array
$t1 = array();//tier1 array
$t2 = array();//tier2 array
$t3 = array();//tier3 array
$t4 = array();//tier4 array
$i=0;//counter variable
function totest($text){
global $t0,$t1,$t2,$t3,$t4,$i;
if(substr($text,0,1) == "+"){
$copy = $text;
$check = false;
while(!$check){
$t0[$i] = $t0[$i].substr($copy,0,1);
$copy=substr($copy,1);
if((substr($copy,0,1)=="@")||(substr($copy,0,1)=="#")||(substr($copy,0,1)=="^")||(substr($copy,0,1)=="|")||(substr($copy,0,1)=="+")){
$check=true;
}
}
$t0[$i] = substr($t0[$i],1);
}if(substr($text,0,1) == "@"){
$copy = $text;
$check = false;
while(!$check){
$t1[$i] = $t1[$i].substr($copy,0,1);
$copy=substr($copy,1);
if((substr($copy,0,1)=="@")||(substr($copy,0,1)=="#")||(substr($copy,0,1)=="^")||(substr($copy,0,1)=="|")||(substr($copy,0,1)=="+")){
$check=true;
}
}
$t1[$i] = substr($t1[$i],1);
}else if(substr($text,0,1) == "#"){
$copy = $text;
$check = false;
while(!$check){
$t2[$i] = $t2[$i].substr($copy,0,1);
$copy=substr($copy,1);
if((substr($copy,0,1)=="@")||(substr($copy,0,1)=="#")||(substr($copy,0,1)=="^")||(substr($copy,0,1)=="|")||(substr($copy,0,1)=="+")){
$check=true;
}
}
$t2[$i] = substr($t2[$i],1);
}else if(substr($text,0,1) == "^"){
$copy = $text;
$check = false;
while(!$check){
$t3[$i] = $t3[$i].substr($copy,0,1);
$copy=substr($copy,1);
if((substr($copy,0,1)=="@")||(substr($copy,0,1)=="#")||(substr($copy,0,1)=="^")||(substr($copy,0,1)=="|")||(substr($copy,0,1)=="+")){
$check=true;
}
}
$t3[$i] = substr($t3[$i],1);
}else if(substr($text,0,1) == "|"){
$copy = $text;
$check = false;
while(!$check){
$t4[$i] = $t4[$i].substr($copy,0,1);
$copy=substr($copy,1);
if((substr($copy,0,1)=="@")||(substr($copy,0,1)=="#")||(substr($copy,0,1)=="^")||(substr($copy,0,1)=="|")||(substr($copy,0,1)=="+")){
$check=true;
}
}
$t4[$i] = substr($t4[$i],1);
}
return $copy;
}
?>
<?php if(isset($_POST['submit'])){
$str = $_POST['Input'];
while($i <= 373){
$str = totest($str);
$i++;
}
$j=0;
while($j <= $i){
if($t0[$j] != null){
$zero = $t0[$j];
$query = "INSERT INTO `pdem_timesheet`.`tblTreeView` VALUES ('$zero','', '','','','','')" ;
mysql_query($query);
}else if($t1[$j] != null){
$first = $t1[$j];
$query = "INSERT INTO `pdem_timesheet`.`tblTreeView` VALUES ('','$first', '','','','','')" ;
mysql_query($query);
}else if($t2[$j] != null){
$second = $t2[$j];
$query = "INSERT INTO `pdem_timesheet`.`tblTreeView` VALUES ('','', '$second','','','','')" ;
mysql_query($query);
}else if($t3[$j] != null){
$third = $t3[$j];
$query = "INSERT INTO `pdem_timesheet`.`tblTreeView` VALUES ('','', '','$third','','','')" ;
mysql_query($query);
}else if($t4[$j] != null){
$fourth = $t4[$j];
$query = "INSERT INTO `pdem_timesheet`.`tblTreeView` VALUES ('','', '','','$fourth','','')" ;
mysql_query($query);
}
$j++;
}
$i=0;
}
?>
any help would be much appreciated, thanks!!!