Hello. I am trying to figure out how to limit the text displayed the product description on the products.php page. I have tried a bunch of things I have found around the web, nothing working.
Tried some stuff with substr but no idea where to or how to put it into the script.
Thanks!
You need to find this code
<?php
if ($mainProduct["description"]):
?>
<?php
print "<p>".substr($mainProduct["description"],0,1000)."</p>";
?>
Thanks nosferatu, I was referring to the wrong script previously!
I recently found this on the php website and have found it quite useful so thought I would share it! It limits the amount of complete words as set in $limit unless it finds a exclamation mark(!) or full stop(.). If you just want to limit it to the number of words change this code
if(($words >= $limit) && ((substr($tok, -1) == "!")||(substr($tok, -1) == ".")))
if ($words >= $limit)
<?php
function summarise($paragraph, $limit){
$tok = strtok($paragraph, " ");
$text="";
$words='0';
while($tok){
$text .= " ".$tok;
$words++;
if(($words >= $limit) && ((substr($tok, -1) == "!")||(substr($tok, -1) == ".")))
break;
$tok = strtok(" ");
}
return ltrim($text);
}
?>
<?php
echo summarise("paragraph to be summarised", 20);
?>
Regards,
Simon.