Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

need help with "htmlspecialchars" code?


jjanguda

Recommended Posts

I just installed Review in products display.. it works fine..

 

 

The problem is if the lengh of the written review text goes over 60 aphabets,

it extends the default box width which doesn't look good.

 

The orginal code source from catalog/product_reviews_info.php

 

<?php echo tep_break_string(nl2br(tep_output_string_protected($review['reviews_text'])), 60, '-<br>')  

 

 

 

But, the code writer used htmlspecialchars($reviews_values['reviews_text'],)

 

 

<?php echo sprintf(tep_image(DIR_WS_IMAGES . 'stars_' . $reviews_values['reviews_rating'] . '.gif', sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $reviews_values['reviews_rating']))) . ' – <i>' . $reviews_values['customers_name'] . ', ' . $date_added . '</i><br>' . htmlspecialchars($reviews_values['reviews_text']) ?>

 

 

 

Macromedia Dreamweaver MX2004 says that the way of using html specialchars is used like this.

 

htmlspecialchars(string string, [int quote_style], [string charset])

 

 

 

Can anyone help me on this matter?

I'd like to limit the number of text to 60 aphabets.

 

I'll appreciate for any help.

Link to comment
Share on other sites

To limit the number oof text with the rewrited code, you could add a substring function, like

 

<?php echo sprintf(tep_image(DIR_WS_IMAGES . 'stars_' . $reviews_values['reviews_rating'] . '.gif', sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $reviews_values['reviews_rating']))) . ' – <i>' . $reviews_values['customers_name'] . ', ' . $date_added . '</i><br>' . substr(htmlspecialchars($reviews_values['reviews_text']),0,60) ?>

Link to comment
Share on other sites

icemaxou, thanks for the code. it works well.

 

 

But i have another problem. I should've said when I previously posted this thread.

 

If the message goes over 60 aphabets, it will display up to 60 apabets only.

 

What I wanted to say was 60 aphabets per line..

 

That's why the orignal code uses '-<br>' after 60. Like this.

 

<?php echo tep_break_string(tep_output_string_protected($reviews['reviews_text']), 60, '-<br>') . ((strlen($reviews['reviews_text']) >= 100) ? '..' : '') . '<br><br><i>' . sprintf(TEXT_REVIEW_RATING, tep_image(DIR_WS_IMAGES . 'stars_' . $reviews['reviews_rating'] . '.gif', sprintf(TEXT_OF_5_STARS, $reviews['reviews_rating'])), sprintf(TEXT_OF_5_STARS, $reviews['reviews_rating'])) . '</i>'; ?>

 

However, the code I should use is this..

 

<?php echo sprintf(tep_image(DIR_WS_IMAGES . 'stars_' . $reviews_values['reviews_rating'] . '.gif', sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $reviews_values['reviews_rating']))) . ' – <i>' . $reviews_values['customers_name'] . ', ' . $date_added . '</i><br>' . substr(htmlspecialchars($reviews_values['reviews_text']),0,60) ?>

 

 

I'm sure there's a way I can make 60 aphabets per line..

 

icemaxou, can you help me one more time?

 

Thanks for all your support!!

Link to comment
Share on other sites

hello jjanguda,

 

This time I think I 've understood what you want, you can try this, I think it would work.

 

echo sprintf(tep_image(DIR_WS_IMAGES . 'stars_' . $reviews_values['reviews_rating'] . '.gif', sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $reviews_values['reviews_rating']))) . ' – <i>' . $reviews_values['customers_name'] . ', ' . $date_added . '</i><br>' . tep_break_string(htmlspecialchars($reviews_values['reviews_text']),60, '-<br>') ?>

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...