jamesjmann Posted February 4, 2011 Share Posted February 4, 2011 echo("<p class=\"commentboxContainer\"><table width=100% border=0> <tr> <td bgcolor=\"#EEE\"><strong><p class=fltlft>$name </strong>says:</p></td> </tr> </table> <table width=100% border=0 bgcolor=\"#EEE\"> <tr> <td width=40%><img src=../images/Icons/People/Anonymous.png width=64 height=64 border=1 /></td> <td width=60%>$comment',0,6</td> </tr> </table> <table width=100% border=0> <tr> <td bgcolor=\"#EEE\" ><p class=fltlft><em>$email</em></p></td> </tr> <tr> <td bgcolor=\"#EEE\" ><p class=fltlft>added on $time</p></td> </tr> </table></p><br>"); Here's my echo statement for displaying comments by users. I want to add a substr (); function to limit the amount of characters of the $comment field. That way if a user makes a long comment it doesn't push the page down. I tried putting it after the echo (); but that didn't work. I also tried putting it before $comment and that didn't even work. I know that if I make two separate echo statements, this can be done, but the field "$comment" is displayed within a table that is part of the original echo statement, so what do I do? Quote Link to comment Share on other sites More sharing options...
jamesjmann Posted February 4, 2011 Author Share Posted February 4, 2011 Ok, half of it is no longer an issue, i.e., breaking it up into three different echo statements doesn't mess up the css. Here's the new code: echo("<p class=\"commentboxContainer\"><table width=100% border=0> <tr> <td bgcolor=\"#EEE\"><strong><p class=fltlft>$name </strong>says:</p></td> </tr> </table> <table width=100% border=0 bgcolor=\"#EEE\"> <tr> <td width=40%><img src=../images/Icons/People/Anonymous.png width=64 height=64 border=1 /></td> <td width=60%>"); echo substr ("$comment,6"); echo ("</td> </tr> </table> <table width=100% border=0> <tr> <td bgcolor=\"#EEE\" ><p class=fltlft><em>$email</em></p></td> </tr> <tr> <td bgcolor=\"#EEE\" ><p class=fltlft>added on $time</p></td> </tr> </table></p><br>"); The problem I'm having now, though, is with the Substr (); I get the error: Warning: Wrong parameter count for substr() What did I do wrong? Quote Link to comment Share on other sites More sharing options...
Zurev Posted February 4, 2011 Share Posted February 4, 2011 You're using the substr function in the context of string,6 - Meaning it's just skipping the first 5 characters? Just make sort of like an excerpt, determine a length you want the maximum to be seen, and have a link to read the rest. Something like: http://danlamanna.com/portfolio/?p=24 Quote Link to comment Share on other sites More sharing options...
jamesjmann Posted February 4, 2011 Author Share Posted February 4, 2011 Problem solved. I realized that I shouldn't have double quoted the inside of the "echo substr();". I tried using single quotes around the variable next, but I learned that when you add single quotes, your telling the echo statement to display precisely what you write within them, whereas if you leave the variable single/double quote free, it outputs the data contained within the variable. I also scripted the numerical values within the function wrong. I only put ($comment, 6); but it should've been ($comment, 0, 50); 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.