Jump to content
  • Checkout
  • Login
  • Get in touch


The e-commerce.

What the... tep_break_string function


Recommended Posts

Ok. while I was writing this I realized that function's objective so im gonna write it only for if someone else needs an explanation =P


First of all, Ive been trying to enlarge the size of the preview text on product_reviews.php


I've found this function where the preview text its output:


<?php echo tep_break_string(tep_output_string_protected($reviews['reviews_text']), 60, '...-<br>') . ((strlen($reviews['reviews_text']) >= 100) ? ' ...' : '') ; ?>


I thought that that function (for its name) was there to specify the large of the preview text so that if I change the 60 for 120 it would be larger, but instead of that, that function prevent from a word like "breeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeak" which could break your web style.


// Break a word in a string if it is longer than a specified length ($len)
 function tep_break_string($string, $len, $break_char = '-') {
   $l = 0;
   $output = '';
   for ($i=0, $n=strlen($string); $i<$n; $i++) {
     $char = substr($string, $i, 1);
     if ($char != ' ') {
     } else {
       $l = 0;
     if ($l > $len) {
       $l = 1;
       $output .= $break_char;
     $output .= $char;

   return $output;


I was going to ask why to look at a word like that but now I undestand its objective, so I post this here for if someone has doubts too and also, I recomend to explain its objective at the reference or at the source comment since its name "tep_break_string" and its place (where you think you should stablish the preview text large) could be confusing.



Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...