限制字的数量PHP Magento即时搜索


Limiting the number of words PHP Magento Instant Search

我试图限制在页面运行时显示的单词数量。我有一个小脚本,我在某些地方使用,但我似乎不能得到任何工作在这种情况下。这里是代码的和平:

    }
    $html .=" <button type='button' class='button-search-buy' onclick='javascript:document.productAddToCartForm.submit()'><span>". $product_helper->__(' ') ."</span></button>";
    $html .="</fieldset>";
}

$html .="<div id='description'><h4 style='margin:5px 0 3px 0'><span style='color:#e26703'>".Mage::helper("catalog/product")->__("Quick Overview")."</span>&nbsp;&nbsp;<a style='font-size:10px' href='".$product_url."'  target='_self'>".$product_helper->__('View Detail')."</a></h4>"
            . $product->getShortDescription() <-------Right here            
      ."</div>"     
."</div>
  </div></form>";
$this->getResponse()->setHeader('Content-type', 'application/x-json');
 $this->getResponse()->setBody($html);      

下面是一些我发现可以工作的代码,但是我不知道如何使它与上面的开放类型php代码一起工作。

<?php $sdesc2 = $_product->getShortDescription();
$sdesc2 = trim($sdesc2);
$limit = 120;
    if (strlen($sdesc2) > $limit) {
      $sdesc2 = substr($sdesc2, 0, strrpos(substr($sdesc2, 0, $limit), ' '));
    } ?>
<?php echo $sdesc2."..."; ?>     
<?php $sdesc2 = $product->getShortDescription();
$sdesc2 = trim($sdesc2);
$limit = 120;
    if (strlen($sdesc2) > $limit) {
      $sdesc2 = substr($sdesc2, 0, strrpos(substr($sdesc2, 0, $limit), ' '));
    } ?>
$html .="<div id='description'><h4 style='margin:5px 0 3px 0'><span style='color:#e26703'>".Mage::helper("catalog/product")->__("Quick Overview")."</span>&nbsp;&nbsp;<a style='font-size:10px' href='".$product_url."'  target='_self'>".$product_helper->__('View Detail')."</a></h4>"
        . $sdesc2 ."</div>"