Jump to content

String length stuff not making up sense?


tallberg

Recommended Posts

I'm getting a weird result from the following code. Thanks if any one can help.

Result:

[quote]start: 0 end: 5000 strlen: 5000

start: 5000 end: 10000 strlen: 8440

start: 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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.