Slicing a selection of text?

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
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Slicing a selection of text?

Post by Joe »

I am in the process of making a user arena where you can view everyones user details. I have done the pagination 'Without all of the javascript' and I am now wondering how I can cut a large selection of text about 170 characters into about 25 characters. It sounds pretty ridiculous asking this but its for a good cause... Any help? The furthest I have got is chop() but that only slices 1 character from the end of a string from what I know...

Regards



Joe 8)
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

[php_man]substr[/php_man]

Code: Select all

<?php
$shorter_text = substr($text, 0, 25);
?>
?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

You could do this

$text = substr($text, 0, 25); //returns first 25 characters

EDIT: GAHHHHHHH JASON YOU BEAT ME BY A HAIR!!!!!!!!!!!!!!!!
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Yeah thanks alot for the help. Worked a treat, ;)


Joe
Post Reply