lingo5 Posted May 28, 2011 Share Posted May 28, 2011 Hi, I´m trying to limit the amount of text outputed from DB to a few lines only. This is how I display the record <?php echo $row_novedades_RS['novedades_descripcion_esp']; ?> and this is a function to limit text output function limit_text($data,$length) { if($length >= strlen($data)) return $data; else return substr($data,0,$length); } I have tried everythin, but I can't figure out how to apply this function to my text so that I can limit the amount of it. Please help. Quote Link to comment https://forums.phpfreaks.com/topic/237726-help-limiting-text-output/ Share on other sites More sharing options...
xyph Posted May 28, 2011 Share Posted May 28, 2011 everything including echo limit_text( $row_novedades_RS['novedades_descripcion_esp'], 100 ); Quote Link to comment https://forums.phpfreaks.com/topic/237726-help-limiting-text-output/#findComment-1221635 Share on other sites More sharing options...
Alex1646 Posted May 28, 2011 Share Posted May 28, 2011 You have to call the function for it to be executed. <?php echo limit_text( $row_novedades_RS['novedades_descripcion_esp'], 100 ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/237726-help-limiting-text-output/#findComment-1221636 Share on other sites More sharing options...
lingo5 Posted May 28, 2011 Author Share Posted May 28, 2011 Thanks guys for your help. It worked great again!! Quote Link to comment https://forums.phpfreaks.com/topic/237726-help-limiting-text-output/#findComment-1221640 Share on other sites More sharing options...
mikesta707 Posted May 28, 2011 Share Posted May 28, 2011 as a side note, creating your own function is kind of pointless. Why not just use substr directly? Quote Link to comment https://forums.phpfreaks.com/topic/237726-help-limiting-text-output/#findComment-1221666 Share on other sites More sharing options...
lingo5 Posted May 29, 2011 Author Share Posted May 29, 2011 Hi Mikesta, you're probably right but I am embarrassingly new to PHP...... Quote Link to comment https://forums.phpfreaks.com/topic/237726-help-limiting-text-output/#findComment-1221831 Share on other sites More sharing options...
mikesta707 Posted May 29, 2011 Share Posted May 29, 2011 its ok. It makes no difference really. Quote Link to comment https://forums.phpfreaks.com/topic/237726-help-limiting-text-output/#findComment-1221844 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.