Click to See Complete Forum and Search --> : RE: substr issues


Sheldon
09-06-2007, 05:32 PM
Ok, I am havinf more issues with substr.

I have this


$te = addslashes("This is a long blurb of text that should span over two lines and it just seams to be repeating the first line.");
if(!empty($te)){
$text .= substr(stripslashes($te),0, 22)."\n";
echo(strlen(stripslashes($te)));
if(strlen(stripslashes($te) > 22)){
$text .= "<br />" . substr(stripslashes($te),23, 38);
}
if(strlen(stripslashes($te)) > 38){ $text .= $text ."..."; }
}
echo($text);

die;


All id does it return the first line 2 times and adds the three ... dots.

What am i doing wrong?

aj_nsc
09-06-2007, 05:58 PM
Well, one thing I've noticed is that you've got a misplaced bracket:

Your code:


if(strlen(stripslashes($te) > 22)){


Correct Code:


if(strlen(stripslashes($te)) > 22){



Other than that, it seems like you logic is totally messed up, substr just returns part of a string, it doesn't remove that from the original $te variable which is what it looks like you think it does in the code.