Wordpress Themes - Debt Consolidation - Livescore euro 2008 - Project Management Software - Manga

PDA

View Full Version : Help with string output limit


EHamilton
Nov 12th 2006, 10:13 pm
What's up? I'm pretty noobish at php and need some help with implementing this code correctly without causing errors. I have a line that reads...

echo " <p class=\"desc\">".$srow['discription']."</p>\n";

I need it to basically read this...

echo "
<p class=\"desc\">
<?
function truncateString($str, $max, $rep = '...') {
if(strlen($str) > $max) {
$leave = $max - strlen($rep);
return substr_replace($str, $rep, $leave);
} else {
return $str;
}
}

print truncateString(".$srow['discription'].", 25);
?>
</p>\n";

What I'm trying to do is set the string to read a certain amount of characters. I know I'm getting an error probably because I'm putting php inside of echo lmfao. Any help is appreciated :o

maiahost
Nov 12th 2006, 11:18 pm
First off you'll get an error on the first echo : here is a bit of modification which worked fine:

<?php
function truncateString($str, $max, $rep = '...') {
if(strlen($str) > $max) {
$leave = $max - strlen($rep);
return substr_replace($str, $rep, $leave);
} else {
return $str;
}}
$s1='saddddddadasdsadasdadsadasdasdasdadasdsadsasd';
$string = truncateString($s1, 25);
echo $string;
?>

if you want to echo something put it inside the <? ?>

EHamilton
Nov 13th 2006, 12:05 am
First off you'll get an error on the first echo : here is a bit of modification which worked fine:

<?php
function truncateString($str, $max, $rep = '...') {
if(strlen($str) > $max) {
$leave = $max - strlen($rep);
return substr_replace($str, $rep, $leave);
} else {
return $str;
}}
$s1='saddddddadasdsadasdadsadasdasdasdadasdsadsasd';
$string = truncateString($s1, 25);
echo $string;
?>

if you want to echo something put it inside the <? ?>

Thanks for the help. I got it to work but I have a list of 3 videos and the first time I only got 1 to show up, I played around with the code a bit and got 2 to show up and the rest of the page was blank. I PMed you the complete code, maybe you can help. Thanks again!