CodeIgniter Forums
need help on substr function on PHP - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: need help on substr function on PHP (/showthread.php?tid=12756)



need help on substr function on PHP - El Forum - 10-30-2008

[eluser]ebot[/eluser]
hello i will love any one to help me out on how to use the substr function on PHP, i will like to use it to limit the number of characters displayed. i don't know if anyone knows where i can get more informations on this

thanks for any help


need help on substr function on PHP - El Forum - 10-30-2008

[eluser]freshface[/eluser]
http://www.php.net/substr


need help on substr function on PHP - El Forum - 10-30-2008

[eluser]Joe_Archer[/eluser]
Code:
substr(string,starting character,[ending character])

ending character is optional.
first character is 0
last character is -1
so to get the first 4 characters of 'Hello' you would do

Code:
substr('Hello',0,3)

if you just want to limit the number of characters displayed in a view, i suggest using Codeigniter's Text Helper which has both word_limiter() and character_limiter() functions.

http://ellislab.com/codeigniter/user-guide/helpers/text_helper.html


need help on substr function on PHP - El Forum - 10-31-2008

[eluser]ebot[/eluser]
Thanks everyone for all help i am greatful you know.
God keep everyone,