brainbug Posted April 12, 2011 Share Posted April 12, 2011 I'm trying to retrieve a record from the database (from a VARCHAR field), but I need to display only 1 line (about first 50 characters) and print it in the page. For eg. if in the varchar field in the table, data is is:-------------------------------------------------------This is W3Schools Forum. I am asking a question in the forum expecting some answers as help. Thank you for help.-------------------------------------------------------But I need to display something like:--------------------------------------------------------This is W3Schools Forum. I am asking a ..(more)--------------------------------------------------------And when the user clicks 'more', he can read the full data.How can I set a limit to how many characters are echoed in the file? Link to comment Share on other sites More sharing options...
Ingolme Posted April 12, 2011 Share Posted April 12, 2011 You can use PHP string function to only show a portion of the retrieved string: echo substr($myString, 0, 50); Here's a reference for the substr function: http://es2.php.net/substr Link to comment Share on other sites More sharing options...
brainbug Posted April 12, 2011 Author Share Posted April 12, 2011 You can use PHP string function to only show a portion of the retrieved string:echo substr($myString, 0, 50); Here's a reference for the substr function: http://es2.php.net/substr Thank you so much. That worked just fine. Exactly as I wanted. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.