Re: 'the missing character'

From: Date: Wed, 16 May 2001 16:25:14 +0000
Subject: Re: 'the missing character'
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-9356@lists.php.net to get a copy of this message
I don't understand xcount(). Instead of xcount(), why not use strlen()? Say we have 7100 chars.... If you step through, first pass $i = 0 $chunk_count = 2 $start = 0 $final = 3500 $text[] is chars 0-3499 second pass $i = 1 // from $i++ $chunk_count = 2 $start = 3501 // problem is here - note the endpoint of the last pass in $text[]? $final = 3499 $text[] is chars 3501-7000 // what happened to char 3500 itself? Remember that substr() takes a start point, and an offset - not an endpoint. So after the first pass, you've read in 0-3499 as is correct, but you have an extraneous if() clause that inc's your start by one, and then adds 3500. Drop the second if($start == 0) clause which sets $start to 1. 'Luck -Szii ----- Original Message ----- From: "Jimmy Brake" <jimmy@cp.net> To: <php-db@lists.php.net> Sent: Tuesday, May 15, 2001 9:54 PM Subject: [PHP-DB] 'the missing character' > Hi! > > Does anyone know of a function in php that will take a chunk of text and seperate it into 'chunks' preferably returning it in an array? > > The reason being is that I have some columns(oracle) that are set to varchar2(4000) and I have text that is 4000+ AND :-) I cannot change it to another format. > > I was unable to find a chunk maker so I built one. > > function chunk_maker($text) > { > // have to count the number of characters, if over 3500 characters need to split into chunks of 3500 characters > $count = xcount($text); > if($count > 3500) > { > $chunk_count = $count/3500; > //need to clean up the $chunk_count by removing the trailing decimals and > //adding one to the total to make sure we do not loose in characters > $chunk_count = floor($chunk_count)+1; > $i=0; > $start=0; > while($i != $chunk_count) > { > // err well this helps to make sure we get the correct amount of characters > if($start == 0) > { > $final = 3500; > } else { > $final = 3499; > } > > //now we need to make the chunks and stick them in an array > > $text2[]=substr($text,$start,$final); > > // err well this helps to make sure we get the correct amount of characters > if($start == 0) > { > $start=1; > } > $start=$start+3500; > $i++; > } > } else { > $text2[] = $text; > } > return($text2); > } > > function xcount($text) > { > global $debug; > foreach (count_chars($text) as $my_value) $length=$length+$my_value; > tracker($length); > return($length); > } > > > If I just failed to find the right functions please let me know, otherwise please help! :-) > > > Jimmy Brake > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#9356) next »