tallberg Posted January 24, 2007 Share Posted January 24, 2007 I'm getting a weird result from the following code. Thanks if any one can help.Result:[quote]start: 0 end: 5000 strlen: 5000start: 5000 end: 10000 strlen: 8440start: 10000 end: 15000 strlen: 3440[/quote]I would of thought the strlen could only be 5000 as the start and end of the substr function are incrementing by 5000.[code]$start = 0; $end = 5000; for($i=1; $i <= $pages; $i++) { $p_Tempdescription = substr($p_description,$start,$end); echo "<br>"; echo "start: " . $start . " end: ". $end . " strlen: " . strlen($p_Tempdescription); echo "<br>"; $start += 5000; $end += 5000; }[/code] Link to comment https://forums.phpfreaks.com/topic/35532-string-length-stuff-not-making-up-sense/ Share on other sites More sharing options...
Jessica Posted January 24, 2007 Share Posted January 24, 2007 The third parameter of substr is not end, but length.So you're saying$p_Tempdescription = substr($p_description,$start,$end);$p_Tempdescription = substr($p_description,0,5000);$p_Tempdescription = substr($p_description,5000,10000); <- sub string will be 10,000 chars, not 5000.Keep your third param 5000 each time. Link to comment https://forums.phpfreaks.com/topic/35532-string-length-stuff-not-making-up-sense/#findComment-168206 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.