You are here:  » Description text and html entities

Support Forum



Description text and html entities

Submitted by Patate on Wed, 2007-02-28 22:23 in

Hi !

Very good script ! Thank you !
I've got a problem with text description and html entities. Sometimes the cut (230 caracters) split a html entities... So I've got an "&eac" in the decription, etc...
How can I define cutting with a number of words ?

Thank you

Submitted by support on Thu, 2007-03-01 09:36

Hi,

I have posted a similar solution before to break the description on a word boundary during import; but the same technique can be used to make sure the break is on a space when the description is cropped for the search results.

Currently, the description is cropped by this line in html/searchresults.php (line 20):

          <p><?php print substr($product["description"],0,250); ?></p>

To break on the nearest word _after_ 250 characters, replace the above with the following:

          <p>
          <?php
          $breakLimit = 250;
          if (strlen($product["description"]) > $breakLimit)
          {
            // find the first space after the limit
            $breakOffset = strpos($product["description"]," ",$breakLimit);
            // if found, crop the description and add "..."
            if ($breakOffset !== false)
            {
              $product["description"] = substr($product["description"],0,$breakOffset)."...";
            }
          }
          print $product["description"];
          ?>
          </p>

Simply change the value of $breakLimit for more or less description...

Hope this helps!
Cheers,
David.