anujgarg Posted April 17, 2009 Share Posted April 17, 2009 Hi Everyone, I have a string that has been truncated with having the last word intact. This string contains Read More phrase in the end. So, if I click on this Read More phrase, I redirect it to the another page. I want to keep it on the same page and want to expand the full text (that was previously truncated). Do I need to use <div> for that along with AJAX or only <div> is enough?? If anyone has a code snippet related to my problem then it can give me a right way to move ahead... Any help regarding this will be highly appreciated. Thanks Anuj Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 17, 2009 Share Posted April 17, 2009 Take a look at this post from a few days ago. Several solutions are provided. http://www.phpfreaks.com/forums/index.php/topic,247661.0.html Quote Link to comment Share on other sites More sharing options...
anujgarg Posted April 17, 2009 Author Share Posted April 17, 2009 Thanks mjdamato for your quick reply... But in the post (link), you provided here, is showing the text that completely hides and shows on clicking the link. Will the foolowing example given by you provides the exact result what I am looking for (without splitting by HTML tags within the text): $index = 1; $maxLength = 50; //max characters to show for the preview while ($record = mysql_fetch_assoc($result)) { $text = $record['text']; //Determin if preview is needed $preview = (strlen($text)>$maxLength); if ($preview) { echo "<a href=\"#\" onclick=\"showHide({$index});\" id=\"display_{$index}\">Show</a><br>\n"; } echo "<div id=\"text_{$index}\">\n"; if ($preview) { //Preview needed, break out the text on the space before $maxLength //Determine the break point $tempString = substr($text, 0, $maxLength+1); $breakPoint = strrpos($tempString, ' '); //Display the text parts echo "<span>" . substr($text, 0, $breakPoint) . "</span>"; echo "<span id=\"ellipse_{$index}\">...</span>"; echo "<span id=\"full_{$index}\" style=\"display:none;\">" . substr($text, $breakPoint) . "</span>"; } else { //No preview needed, display entire text string echo $text; } echo "</div><br><br>\n"; $index++; } Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 17, 2009 Share Posted April 17, 2009 Either you are not understanding the code provided int he otehr post or I am not undestanding you. Here is what I understood in your first post: You stated that you are displaying text which has been truncated and that upon clicking the "Read More" link the user is redirected to another page to read the entire text. instead you wnat the entire text to be displayed on the same page without a redirect. That is what I provided in the code in the other post I directed you to. The code snipped you posted above was the code to be run on the PHP side to determine what truncated and full text to be used. There is no splitting by HTML tags. You apparently already have code to truncate how you wish, so you would just need to use the code above as a guide to modify your current process. The full text needs to be split into the truncated and non-truncated text and put into DIV or SPAN containers, which the JS code will then use to display/hide the truncated text. Quote Link to comment 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.