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.
?>

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.