Okay folks, I am trying to put a character limit on a body of text. I am using the following function, which is place in the _func.php file:
function wordLimiter($str, $limit = 120, $endstr = '…'){
$str = strip_tags($str);
if(strlen($str) <= $limit) return $str;
$out = substr($str, 0, $limit);
$pos = strrpos($out, " ");
if ($pos>0) {
$out = substr($out, 0, $pos);
}
return $out .= $endstr;
}
This works just fine on it's own. When placed in Hanna code I get a fatal error, "Call to undefined function wordLimiter()". Code in hanna
<?php
echo "<div class=\"grid_xs-1\">";
foreach ($pages->find("template=property") as $properties) {
//attempt at defining $summ to call wordLimitor()
$summ = wordLimiter($properties->body);
echo "
<div class=\"col-5 card property\">
<a href=\"{$properties->url}\">
<img src=\"{$properties->images->first->size(500,500)->url}\">
</a>
</div>
<div class=\"col-7\">
<h3>{$properties->title}</h3>
<p>{$summ}</p>
</div>
<div class=\"col-12 grid details\">
<div class=\"col\">
<i class=\"fa fa-dollar\" aria-hidden=\"true\"></i>
{$properties->price}</div>
<div class=\"col\">
<i class=\"fa fa-bed\" aria-hidden=\"true\"></i>
{$properties->bedroom}</div>
<div class=\"col\">
<i class=\"fa fa-bath\" aria-hidden=\"true\"></i>
{$properties->bathroom} </div>
<div class=\"col\">
<i class=\"fa fa-arrows\" aria-hidden=\"true\"></i>
{$properties->square_feet} SqFt</div>
</div>";
}
echo "</div>";
I have also tried placing the function wordLimiter() at the top of the Hanna but it give a different error, " Cannot redeclare wordLimiter() "
Am I missing something here? Limitation somewhere?