Jump to content

Read more... if text more than 600 characters


NealeWeb

Recommended Posts

The theory would be like this:

 

<?php
$t = "Your text goes here Your text goes here Your text goes here Your text goes here Your text goes here Your text goes here Your text goes here Your text goes here Your text goes here";
echo substr($t,0,10), (strlen($t) > 10) ? ' <a href="yourlink">more...</a>' : ''; // taken 10 as limit. you can use 600 here or make it a variable.
?>

Link to comment
Share on other sites

Ok sorry onne more thing i am trying to use this in an existing echo but im having trouble.

 

I get this error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'  on line 48

 

This is what i have tried:

echo '<div align="center">
<table border="0" cellpadding="10" cellspacing="0" width="969" background="imgs/reviewbox.png" height="157">
	<tr>
		<td height="19" ><span class="font1">' . $jtitle . '</span></td>
		<td height="19" >
		<p align="right"><a href="review.php?review_id=' . $revid . '"><span class="font">View Full review</span></a></td>
	</tr>
	<tr>
		Line 48 >>> <td valign="top" colspan="2"><span class="font">substr($t,0,, (strlen($t) >  ? ' <a href="yourlink">Read more...</a>' : '';</span></td> <<< Line 48
	</tr>
</table>
</div>';

 

Is it possible to make it a variable like this in any way:

<?php
$t = "Your text";
$y= substr($t,0,, (strlen($t) >  ? ' <a href="yourlink">Read more...</a>' : '';
echo $y;

?>

 

I am very new at php so im sure im making some pretty silly mistakes.

Link to comment
Share on other sites

No worries. Here you go:

echo '<div align="center">
  <table border="0" cellpadding="10" cellspacing="0" width="969" background="imgs/reviewbox.png" height="157">
    <tr>
      <td height="19" ><span class="font1">' . $jtitle . '</span></td>
      <td height="19" >
      <p align="right"><a href="review.php?review_id=' . $revid . '"><span class="font">View Full review</span></a></td>
    </tr>
    <tr>
      <td valign="top" colspan="2"><span class="font">' . substr($t,0, . ((strlen($t) >  ? ' <a href="yourlink">Read more...</a>' : '') . '</span></td>
    </tr>
  </table>
</div>';

 

If you are trying to take a variable, do this:

<?php
$t = "Your text";
$y = substr($t,0, . ((strlen($t) >  ? ' <a href="yourlink">Read more...</a>' : ''); // see that I have enclosed the conditional statement in braces.
echo $y;
?>

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.