[Skip to main content](#vessel-content)

#   afficher que les 200 premiers caractères d'une vue

##

- **[toffffe](/forum/user/4564-toffffe "View toffffe's Profile")**
- [![toffffe's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/4564-toffffe "View toffffe's Profile") Topic Author
- [ Offline](/forum/user/4564-toffffe)

Less More

- Posts: 318
- Thank you received: 1
-
-
-
- [](http://www.agence-web-inoak.fr)
-

14 years 4 months ago -  14 years 4 months ago [\#52777](#52777) by [toffffe](/forum/user/4564-toffffe "View toffffe's Profile")  *[afficher que les 200 premiers caractères d'une vue](/forum/5-support-en-francais-french-support-/52777-afficher-que-les-200-premiers-caracteres-dune-vue#52777 "Bonjour, Avec Hikashop j'ai modifié la vue produit / listing&#95;img&#95;desc pour afficher que les 240 premiers caractères et ensuite mettre un &#91;...&#93; Le problème c'est que mon code tient compte du code html et donc des fois m'affiche des balises html du style ")* was created by *[toffffe](/forum/user/4564-toffffe "View toffffe's Profile")*

Bonjour,
Avec Hikashop j'ai modifié la vue produit / listing_img_desc
pour afficher que les 240 premiers caractères et ensuite mettre un [...]
Le problème c'est que mon code tient compte du code html et donc des fois m'affiche des balises html du style &lt; [...]
voici mon code :

> &lt;div class="hikashop\_product\_desc" style="text-align:&lt;?php echo $this-&gt;align; ?&gt;"&gt;
> &lt;?php
> $descr = mb\_substr($this-&gt;row-&gt;product\_description, 0,240);
> $len = mb\_strlen( $this-&gt;row-&gt;product\_description ) ;
> if ( $len &gt;= 240 ){ $descr .= ' \[...\]' ;
> }
> echo preg\_replace('#&lt;hr \*id="system-readmore" \*/&gt;.\*#is','',$descr);
> ?&gt;

savez vous où est mon erreur ou connaissez-vous une autre solution ?
Merci

---

Agence web e-commerce spécialiste Hikashop

Last edit: 14 years 4 months ago by [toffffe](/forum/user/4564-toffffe "View toffffe's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzUtc3VwcG9ydC1lbi1mcmFuY2Fpcy1mcmVuY2gtc3VwcG9ydC0vNTI3NzctYWZmaWNoZXItcXVlLWxlcy0yMDAtcHJlbWllcnMtY2FyYWN0ZXJlcy1kdW5lLXZ1ZT90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[Xavier](/forum/user/4105-xavier "View Xavier's Profile")**
- [![Xavier's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4105.png)](/forum/user/4105-xavier "View Xavier's Profile")
- [ Offline](/forum/user/4105-xavier)

Less More

- Posts: 13201
- Thank you received: 2322
-
-
-
- [](http://www.kidiweb.fr)
-

14 years 4 months ago [\#52813](#52813) by [Xavier](/forum/user/4105-xavier "View Xavier's Profile")  Replied by *[Xavier](/forum/user/4105-xavier "View Xavier's Profile")* on topic *[Re: afficher que les 200 premiers caractères d'une vue](/forum/5-support-en-francais-french-support-/52777-afficher-que-les-200-premiers-caracteres-dune-vue#52813 "Bonjour, Avec Hikashop j'ai modifié la vue produit / listing&#95;img&#95;desc pour afficher que les 240 premiers caractères et ensuite mettre un &#91;...&#93; Le problème c'est que mon code tient compte du code html et donc des fois m'affiche des balises html du style ")*

Bonjour toffffe,

Vous devriez essayer avec : mb_strcut().
Cette fonction permet de couper une chaine de caractères en bytes et non en caractères.
Ce qui fais qu'elle doit prendre en compte les balises et non pas seulement les caractères spéciaux.

A voir.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzUtc3VwcG9ydC1lbi1mcmFuY2Fpcy1mcmVuY2gtc3VwcG9ydC0vNTI3NzctYWZmaWNoZXItcXVlLWxlcy0yMDAtcHJlbWllcnMtY2FyYWN0ZXJlcy1kdW5lLXZ1ZT90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[toffffe](/forum/user/4564-toffffe "View toffffe's Profile")**
- [![toffffe's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/4564-toffffe "View toffffe's Profile") Topic Author
- [ Offline](/forum/user/4564-toffffe)

Less More

- Posts: 318
- Thank you received: 1
-
-
-
- [](http://www.agence-web-inoak.fr)
-

14 years 4 months ago [\#52815](#52815) by [toffffe](/forum/user/4564-toffffe "View toffffe's Profile")  Replied by *[toffffe](/forum/user/4564-toffffe "View toffffe's Profile")* on topic *[Re: afficher que les 200 premiers caractères d'une vue](/forum/5-support-en-francais-french-support-/52777-afficher-que-les-200-premiers-caracteres-dune-vue#52815 "Bonjour, Avec Hikashop j'ai modifié la vue produit / listing&#95;img&#95;desc pour afficher que les 240 premiers caractères et ensuite mettre un &#91;...&#93; Le problème c'est que mon code tient compte du code html et donc des fois m'affiche des balises html du style ")*

Non pour moi ça ne fonctionne pas ![:-(](/media/kunena/emoticons/22.png ":-(")
Mais merci quand même je ne dis pas que le problème vient de vous mais peut être de mon code

---

Agence web e-commerce spécialiste Hikashop

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzUtc3VwcG9ydC1lbi1mcmFuY2Fpcy1mcmVuY2gtc3VwcG9ydC0vNTI3NzctYWZmaWNoZXItcXVlLWxlcy0yMDAtcHJlbWllcnMtY2FyYWN0ZXJlcy1kdW5lLXZ1ZT90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[toffffe](/forum/user/4564-toffffe "View toffffe's Profile")**
- [![toffffe's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/4564-toffffe "View toffffe's Profile") Topic Author
- [ Offline](/forum/user/4564-toffffe)

Less More

- Posts: 318
- Thank you received: 1
-
-
-
- [](http://www.agence-web-inoak.fr)
-

14 years 4 months ago [\#52828](#52828) by [toffffe](/forum/user/4564-toffffe "View toffffe's Profile")  Replied by *[toffffe](/forum/user/4564-toffffe "View toffffe's Profile")* on topic *[Re: afficher que les 200 premiers caractères d'une vue](/forum/5-support-en-francais-french-support-/52777-afficher-que-les-200-premiers-caracteres-dune-vue#52828 "Bonjour, Avec Hikashop j'ai modifié la vue produit / listing&#95;img&#95;desc pour afficher que les 240 premiers caractères et ensuite mettre un &#91;...&#93; Le problème c'est que mon code tient compte du code html et donc des fois m'affiche des balises html du style ")*

En fait pour être clair ce qui se passe c'est que mon code compte bien les caractères, mais le problème c'est que lorsque le 240ème caractère est une balise de fermeture &lt;p&gt; et bien il affiche :
la fin de la phrase&lt;[...]

---

Agence web e-commerce spécialiste Hikashop

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzUtc3VwcG9ydC1lbi1mcmFuY2Fpcy1mcmVuY2gtc3VwcG9ydC0vNTI3NzctYWZmaWNoZXItcXVlLWxlcy0yMDAtcHJlbWllcnMtY2FyYWN0ZXJlcy1kdW5lLXZ1ZT90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[toffffe](/forum/user/4564-toffffe "View toffffe's Profile")**
- [![toffffe's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/4564-toffffe "View toffffe's Profile") Topic Author
- [ Offline](/forum/user/4564-toffffe)

Less More

- Posts: 318
- Thank you received: 1
-
-
-
- [](http://www.agence-web-inoak.fr)
-

14 years 4 months ago [\#52833](#52833) by [toffffe](/forum/user/4564-toffffe "View toffffe's Profile")  Replied by *[toffffe](/forum/user/4564-toffffe "View toffffe's Profile")* on topic *[Re: afficher que les 200 premiers caractères d'une vue](/forum/5-support-en-francais-french-support-/52777-afficher-que-les-200-premiers-caracteres-dune-vue#52833 "Bonjour, Avec Hikashop j'ai modifié la vue produit / listing&#95;img&#95;desc pour afficher que les 240 premiers caractères et ensuite mettre un &#91;...&#93; Le problème c'est que mon code tient compte du code html et donc des fois m'affiche des balises html du style ")*

J'ai modifié mon code en métant

> &lt;div class="hikashop\_product\_desc" style="text-align:&lt;?php echo $this-&gt;align; ?&gt;"&gt;
> &lt;?php
>
> $descr2 = strip\_tags(mb\_substr($this-&gt;row-&gt;product\_description, 0,240));
> $len = mb\_strlen( $this-&gt;row-&gt;product\_description ) ;
> if ($len &gt;= 240 ){ $descr2 .= ' \[...\]' ;
> }
> $descr = $descr2;
> echo preg\_replace('#&lt;hr \*id="system-readmore" \*/&gt;.\*#is','',$descr);
> ?&gt;
> &lt;/div&gt;

Mais le problème c'est que la il affiche plus le texte avec la mis en forme ![:(](/media/kunena/emoticons/22.png ":(")

---

Agence web e-commerce spécialiste Hikashop

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzUtc3VwcG9ydC1lbi1mcmFuY2Fpcy1mcmVuY2gtc3VwcG9ydC0vNTI3NzctYWZmaWNoZXItcXVlLWxlcy0yMDAtcHJlbWllcnMtY2FyYWN0ZXJlcy1kdW5lLXZ1ZT90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86323
- Thank you received: 14283
-
-

14 years 4 months ago [\#52924](#52924) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: afficher que les 200 premiers caractères d'une vue](/forum/5-support-en-francais-french-support-/52777-afficher-que-les-200-premiers-caracteres-dune-vue#52924 "Bonjour, Avec Hikashop j'ai modifié la vue produit / listing&#95;img&#95;desc pour afficher que les 240 premiers caractères et ensuite mettre un &#91;...&#93; Le problème c'est que mon code tient compte du code html et donc des fois m'affiche des balises html du style ")*

Je ne vois pas de solution pour couper du texte "intélligement"... Il faudrait pouvoir analyser le code HTML pour faire cela et ca serait beaucoup beaucoup plus compliqué...

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzUtc3VwcG9ydC1lbi1mcmFuY2Fpcy1mcmVuY2gtc3VwcG9ydC0vNTI3NzctYWZmaWNoZXItcXVlLWxlcy0yMDAtcHJlbWllcnMtY2FyYWN0ZXJlcy1kdW5lLXZ1ZT90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[toffffe](/forum/user/4564-toffffe "View toffffe's Profile")**
- [![toffffe's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/4564-toffffe "View toffffe's Profile") Topic Author
- [ Offline](/forum/user/4564-toffffe)

Less More

- Posts: 318
- Thank you received: 1
-
-
-
- [](http://www.agence-web-inoak.fr)
-

14 years 4 months ago [\#52981](#52981) by [toffffe](/forum/user/4564-toffffe "View toffffe's Profile")  Replied by *[toffffe](/forum/user/4564-toffffe "View toffffe's Profile")* on topic *[Re: afficher que les 200 premiers caractères d'une vue](/forum/5-support-en-francais-french-support-/52777-afficher-que-les-200-premiers-caracteres-dune-vue#52981 "Bonjour, Avec Hikashop j'ai modifié la vue produit / listing&#95;img&#95;desc pour afficher que les 240 premiers caractères et ensuite mettre un &#91;...&#93; Le problème c'est que mon code tient compte du code html et donc des fois m'affiche des balises html du style ")*

Merci donc à tous les 2
J'ai donc fait une adaptation d'un code php trouvé ici [ mikinfo.free.fr/index.php/quelques-fonctions-pratiques-en-php/](http://mikinfo.free.fr/index.php/quelques-fonctions-pratiques-en-php/)
Ce code est bien pratique malgré quelques défauts : il compte qu'approximativement les caractères puisque le html est compté aussi
Mais au moins il a le mérite de répondre à mon besoin
Voici le code modifié ci il intéresse quelqu'un d'autre je m'en suis servi dans la vue product/ listing image description de Hikashop Code:

&lt;div class="hikashop_product_desc" style="text-align:&lt;?php echo $this-&gt;align; ?&gt;"&gt; &lt;?php $length= 240; $text = ($this-&gt;row-&gt;product_description); if (mb_strlen($text, 'UTF-8') &gt; $length) { $text = mb_substr($text, 0, $length, 'UTF-8'); $text = mb_substr($text, 0, mb_strrpos($text, ' ', -1, 'UTF-8'), 'UTF-8'); $text .= '&amp;nbsp;[&amp;hellip;]'; echo $text; } else {echo $this-&gt;row-&gt;product_description;} ?&gt; &lt;/div&gt;

Encore merci à vous pour votre aide

---

Agence web e-commerce spécialiste Hikashop

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzUtc3VwcG9ydC1lbi1mcmFuY2Fpcy1mcmVuY2gtc3VwcG9ydC0vNTI3NzctYWZmaWNoZXItcXVlLWxlcy0yMDAtcHJlbWllcnMtY2FyYWN0ZXJlcy1kdW5lLXZ1ZT90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.072 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
