Page 1 of 1
Selecting first 25 chars of a string.
Posted: Fri Jan 02, 2009 2:21 pm
by Mightywayne
I need to get the first 25 chars of a string into another variable. That's it. The variable can be like 500 chars and I just need to take the first 25 and display them. (it's a preview script sorta thing)
Code: Select all
$message = chunk_split($message,25,"...");
chunk_split is the best I can find and it isn't even doing what I need it to.

Re: Selecting first 25 chars of a string.
Posted: Fri Jan 02, 2009 2:23 pm
by Syntac
Re: Selecting first 25 chars of a string.
Posted: Fri Jan 02, 2009 2:24 pm
by andyhoneycutt
try
the substring function
Code: Select all
$message = "asdfasdf...";
$start = 0; // the first character of the string.
$end = 25; // grab 25 characters from $start.
$preview = substr($message,$start,$end);
echo $preview;
-Andy
Re: Selecting first 25 chars of a string.
Posted: Fri Jan 02, 2009 3:07 pm
by Mightywayne
Oh, I guess I misunderstood substr. Thanks a lot, guys, I feel dumb now.
