pda4me
asked on
PHP echo limit characters
How do I adjust the results of this echo statement to limit the output to the first 25 characters found in the record?
<table class="WADAResultsTable" border="0" cellpadding="0" cellspacing="0">
<?php do {
$sText = $row_WADAnews['text'];
$sModifyText = str_replace("<img ","<img width='90' height='113' ",$sText);
?>
<tr>
<td style="text-align: justify;">
<?php echo($sModifyText); ?><br>
</td>
<?php } while ($row_WADAnews = mysql_fetch_assoc($WADAnews)); ?>
</table>
echo( substr($sModifyText, 0, 15));
?
Or are you trying to achieve something else?
?
Or are you trying to achieve something else?
i thinks he needs
$sText = substr($row_WADAnews['text '],0,25);
at line 3 of his code
$sText = substr($row_WADAnews['text
at line 3 of his code
You can truncate the string as shown by my2eggs and stevepicks, or you can break it apart on a word boundary if you are willing to write a little more code, but the question appears to be illogical, and here is why.
On line 3 you get a variable called $sText out of a data base row.
On line 4, you replace 4 characters of this field with a string that is 30 characters long.
Thus you have added 26 characters to the contents of this variable, which makes "limit the output to the first 25 characters" something that is hard to grok.
Can you please explain what you are trying to achieve? If we understand the inputs and the desired outputs we may be able to offer more productive suggestions. Thanks, ~Ray
On line 3 you get a variable called $sText out of a data base row.
On line 4, you replace 4 characters of this field with a string that is 30 characters long.
Thus you have added 26 characters to the contents of this variable, which makes "limit the output to the first 25 characters" something that is hard to grok.
Can you please explain what you are trying to achieve? If we understand the inputs and the desired outputs we may be able to offer more productive suggestions. Thanks, ~Ray
ASKER
I was looking for along the lines of stevepicks solution but it does not appear to work...is there a syntax issue? Good point Ray, the 25 limit I specified was just a number I planned on changing once I see how the data displays...I am shooting for more along the lines of 175 characters. Any suggestions?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://php.net/manual/en/function.substr-replace.php
I believe there are other ways to do this other than creating your own function. I'll repost if I find it.
Open in new window