Selecting first 25 chars of a string.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Selecting first 25 chars of a string.

Post 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. :(
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: Selecting first 25 chars of a string.

Post by Syntac »

User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Selecting first 25 chars of a string.

Post 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
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Re: Selecting first 25 chars of a string.

Post by Mightywayne »

Oh, I guess I misunderstood substr. Thanks a lot, guys, I feel dumb now. :|
Post Reply