Resources for Developers Using Amazon's Product Advertising API
· Home  
· Search  
· Browse Nodes  
· Data Feed?  
· FAQs  
· One-Second Rule  
· PHP Examples  
· Tips for Associates  
· Tools  
· Understanding A2S  

Create a custom Amazon Associate Store in minutes with
Associate-O-Matic.

Disappointed by Amazon.com and the Associates program?

Please consider
Shareasale

Shareasale manages affiliate programs for thousands of merchants. The site makes it easier to apply to programs and create links. And simple-to-use datafeeds are offered by most merchants.

Trimming Descriptions and Reviews

Often you would like to trim a product description or customer review to a shorter length. The following PHP function will trim a string to a desired length. It breaks the string at a space.

function cutString($text, $limit)
 {
  $text = strip_tags($text);
  if (strlen($text) > $limit)
    {
     $x = $limit;
     while ($x > ($limit * .8))
      {
       --$x;
       if (substr($text, $x, 1) == ' ') break;
      }
     $text = substr($text, 0, $x);
     return $text . "...";
    }
   else
    {
     return $text;
    }
 }

Copyright © 2019 by Roger Smith