poleposters Posted May 15, 2008 Share Posted May 15, 2008 Hi, I have a 400 character description in my database. I want my users to be shown a preview of the description. ie the first 100 characters. How can I do this? Cheers. Link to comment https://forums.phpfreaks.com/topic/105733-how-do-i-display-the-first-100-characters-of-a-record/ Share on other sites More sharing options...
redarrow Posted May 15, 2008 Share Posted May 15, 2008 <?php $mess="my name is redarrow i love php so much man"; $res=substr($mess,0,19); // 0 means start from 1 to example 19... echo $res; ?> you need this awell i thort mate <?php $mess="my name is redarrow i love php so much man"; $res=wordwrap($mess,19,'<br>');// make a br at charecter 19.. echo $res; ?> Link to comment https://forums.phpfreaks.com/topic/105733-how-do-i-display-the-first-100-characters-of-a-record/#findComment-541735 Share on other sites More sharing options...
blueman378 Posted May 15, 2008 Share Posted May 15, 2008 youll need something like this: SELECT LEFT(`CP:_NAME`,100) FROM TABLE_NAME this way will acctually only physically select the first 100 chars Link to comment https://forums.phpfreaks.com/topic/105733-how-do-i-display-the-first-100-characters-of-a-record/#findComment-541736 Share on other sites More sharing options...
redarrow Posted May 15, 2008 Share Posted May 15, 2008 for mysql use SUBSTRING mate............ Link to comment https://forums.phpfreaks.com/topic/105733-how-do-i-display-the-first-100-characters-of-a-record/#findComment-541746 Share on other sites More sharing options...
poleposters Posted May 15, 2008 Author Share Posted May 15, 2008 Great! Thanks, but I just realised I need to do one more thing. I'm using FCK editor to include HTML tags in the description. So my description. Looks like this. <p>my name is redarrow i love php so much man</p> <p> my name is poleposters and I also love php</p> I need the tags so that my users can create their own formatting for their description. But I don't want to include paragraphs in the preview. Is there a way to remove the tags? Link to comment https://forums.phpfreaks.com/topic/105733-how-do-i-display-the-first-100-characters-of-a-record/#findComment-541785 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.