Forum Moderators: coopster

Message Too Old, No Replies

PHP STRPOS() error, why?

         

madcat

5:55 pm on Jan 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi:

I can't figure out why I get this error as other people have used this exact code on their sites with no problem.

I'm using a shopping cart program and trying to get a description area to use line breaks instead of characters to control the amount of space I have to describe.

Warning: strpos(): Offset not contained in string. in /home/felix/public_html/shop/index.php on line 344

...index.php looks like this...

</tr>";
}
$bgcolour=$colour_4;
while($row = mysql_fetch_array($result))
{ $product=$row["product"];
$description= $row["description"];
$price=$row["price"];
$sale_price=$row["sale_price"];
$image=$row["image"];
$title=$row["title"];
$title=stripslashes($title);
$description=stripslashes($description);
while ($br_count < 4)
{
$br=strpos($description,"<br>",$br);
$br=$br+1;
$br_count++;
}
$br=$br-1;
$description=substr($description,0,$br);
$br=0;
$br_count=0;
//$description=substr($description,0,100);

Thank you for any help...!

coopster

7:55 pm on Jan 8, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You may need to initialize that offset before the first iteration of that loop:
$br = 0; 
while ($br_count < 4)
{
$br=strpos($description,"<br>",$br);
$br=$br+1;
$br_count++;
}

madcat

11:57 pm on Jan 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hmm, thanks for trying. The errors don't even budge...

jatar_k

5:07 pm on Jan 9, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I would also try initializing it to
$br = 1;

also I would echo the $br var through that while loop to help see what the error is.