bplumb Posted August 29, 2010 Share Posted August 29, 2010 Hi all, I am relatively new to coding but wondered if someone can helpe me with this. I currently have a PHP file which outputs text that has been entered into a text box and saved. The original output code was this: if ( $this->theme->conf->item_description AND $this->doc->data->dmdescription ) : <?php echo $this->doc->data->dmdescription;?> but I want the text that shows to be truncated to say, 100 characters plus '...' so I came up with the following... <?php $someText = ($this->doc->data->dmdescription);?> <?php echo(substr($someText, 0,100)).'...'; ?> However it shows nothing. I guess $someText is bing linked to dmdescription rather than the text within dmdescription? Any ideas greatly appreciated! bplumb Link to comment https://forums.phpfreaks.com/topic/212010-truncating-text-within-a-field/ Share on other sites More sharing options...
Shp0ngl3 Posted August 29, 2010 Share Posted August 29, 2010 This should do the trick <?php echo substr($someText, 0,100).'...'; ?> Link to comment https://forums.phpfreaks.com/topic/212010-truncating-text-within-a-field/#findComment-1104907 Share on other sites More sharing options...
bplumb Posted August 29, 2010 Author Share Posted August 29, 2010 Thanks for the suggestion. Unfortunately I feel we are close but not close enough yet! Here is the error returned... Savant2: template source file not found ( code :-7 ) Catchable fatal error: Object of class Savant2_Error_docman could not be converted to string in (directory address)/list.tpl.php on line 59 Line 59 on this other PHP file is... include $this->loadTemplate('documents/list_item.tpl.php'); (where list_item.tpl.php is the file we are currently trying to add the truncate text to) Link to comment https://forums.phpfreaks.com/topic/212010-truncating-text-within-a-field/#findComment-1104911 Share on other sites More sharing options...
bplumb Posted August 29, 2010 Author Share Posted August 29, 2010 Scrap that, it works a treat! Thank you so much! Link to comment https://forums.phpfreaks.com/topic/212010-truncating-text-within-a-field/#findComment-1104912 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.