Jump to content

Truncating text within a field


bplumb

Recommended Posts

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

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.