Use $firstname
as first parameter instead of $first_name
(which initially contains nothing) while using character_limiter()
function
$firstname = "asdfasdfasdfjkljldkafjsddfjakdsjflaksjdfl";
$first_name = character_limiter($firstname, 10); // limits $firstname to 10 chars and outputs to $first_name
echo $first_name;
In case that was a typo error while you posted your question, then problem might be with loading of Text Helper in Codeigniter which is required for using this function (CI Text Helper).
You can load Text Helper by specifying it in application/config/autoload.php like this:
$autoload['helper'] = array('text');
Or by loading it specifically in a Controller function like this:
$this->load->helper('text');
UPDATE :
Codeigniter maintains "the integrity of words so the character count may be slightly more or less then what you specify" (ref. CI Text Helper)
Let me explain you this by an example:
$firstname = "asdfasdfasdfjkljldkafjsddfjakdsjflaksjdfl"; //contains only single word
$first_name = character_limiter($firstname, 10);
Here, CI tries to limit $firstname
to 10 chars but since, it encounters a word, it will not try to break it instead it outputs till the end of the word.
Now say you had used,
$firstname = "asdfa sdfasdfj kljldkafjsddfjakdsjflaksjdfl sdjbfsdufb";
This contains three words, so the output will be asdfa sdfasdfj…
Note that here too the limited string contains more than 10 chars but since CI tries to maintain word integrity, it does not break the last word.
If you need to strictly limit input string by character, then, you'll have to use the inbuilt php function substr() as described by Hudixt.