Jump to content

Substr ($variable,x,x) In Echo Statement


jamesjmann

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.