CodeIgniter Forums
[Solved] Limit number of letters in string php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: [Solved] Limit number of letters in string php (/showthread.php?tid=63201)



[Solved] Limit number of letters in string php - wolfgang1983 - 10-06-2015

Hi All,

I would like to know if any one knows on codeigniter the best method to limit the number of letters showing in my string

Let's say my implode(' ', $name), then out puts some_test_image_sample.jpg but if I only want it to show max of 6 letters some_te.jpg

What would be best way


PHP Code:
$data['images'][] = array(
'thumb' => '',
'name' => implode(' '$name),
'type' => 'directory',
'path' => utf8_substr($imageutf8_strlen(FCPATH 'image/')),
'href' => site_url('admin/common/filemanager') . '/?directory=' utf8_substr($imageutf8_strlen(FCPATH 'image/' 'catalog/')) . $url
); 



RE: Limit number of letters in string php - pdthinh - 10-06-2015

(10-06-2015, 10:09 PM)riwakawd Wrote: Hi All,

I would like to know if any one knows on codeigniter the best method to limit the number of letters showing in my string

Let's say my implode(' ', $name), then out puts some_test_image_sample.jpg but if I only want it to show max of 6 letters some_te.jpg

What would be best way




PHP Code:
$data['images'][] = array(
'thumb' => '',
'name' => implode(' '$name),
'type' => 'directory',
'path' => utf8_substr($imageutf8_strlen(FCPATH 'image/')),
'href' => site_url('admin/common/filemanager') . '/?directory=' utf8_substr($imageutf8_strlen(FCPATH 'image/' 'catalog/')) . $url
); 

You can use substr of PHP. For example:

PHP Code:
substr(implode(' '$name), 05



RE: Limit number of letters in string php - wolfgang1983 - 10-06-2015

(10-06-2015, 11:34 PM)pdthinh Wrote:
(10-06-2015, 10:09 PM)riwakawd Wrote: Hi All,

I would like to know if any one knows on codeigniter the best method to limit the number of letters showing in my string

Let's say my implode(' ', $name), then out puts some_test_image_sample.jpg but if I only want it to show max of 6 letters some_te.jpg

What would be best way





PHP Code:
$data['images'][] = array(
'thumb' => '',
'name' => implode(' '$name),
'type' => 'directory',
'path' => utf8_substr($imageutf8_strlen(FCPATH 'image/')),
'href' => site_url('admin/common/filemanager') . '/?directory=' utf8_substr($imageutf8_strlen(FCPATH 'image/' 'catalog/')) . $url
); 

You can use substr of PHP. For example:


PHP Code:
substr(implode(' '$name), 05

Thank you for advice and link


RE: [Solved] Limit number of letters in string php - mwhitney - 10-07-2015

I realize you've marked this solved already, but you might want to check out CI's text_helper, especially the character_limiter() and word_limiter() functions.


RE: [Solved] Limit number of letters in string php - wolfgang1983 - 10-07-2015

(10-07-2015, 09:12 AM)mwhitney Wrote: I realize you've marked this solved already, but you might want to check out CI's text_helper, especially the character_limiter() and word_limiter() functions.

Thank you @mwhitney good to know. Here it is with character Limiter, I have attached image


PHP Code:
$data['images'][] = array(
'thumb' => $this->model_image->resize($image100100),
'name' => character_limiter(implode(' '$name), 17),
'type' => 'image',
'path' => substr(strrchr($image"\'"), 13),
'href' => base_url() . 'image/' utf8_substr($imageutf8_strlen(FCPATH 'image/'))
);