I know it seems like its an encoding problem, I don't think so. I have a site where people use ckeditor to post some long text (stories) when the user saves their work some HTML goes to the database which is prepared for utf8 encoding for all tables.
For all posts I generate a "text thumbnail" which is a fragment of the full text, the full text looks good, in all pages I use utf-8.
The code I use to get my "text thumbnail":
<?php
$str = trim(strip_tags(nl2br($historia['texto']))); //get only text
echo substr($str, 0, 99) . (strlen($str) > 100 ? '...' : ''); //get part of string, if original string was longer than 100 characters add 3 dots at the end
?>
By far I have been running the site for more than one month, the problem came with the next and specific string to be treated
<p>Foto artística<br>Mi esposo invito uno de sus viejos amigos a casa, un
hombre muy impresionante, llegó en un auto de lujo, vistiendo finas ropas,
reloj de plata, cadenas de oro y cosas impresionantes, el nos platico de
muchas de las cosas a las que se dedico desde que perdió la comunicación
con mi esposo, desde ayudante de cocina hasta productor de películas
independientes que había logrado vender por sumas importantes de dinero,
el motivo de su visita era porque necesitaba a alguien como mi esposo
para salir en una de sus filmaciones, a cambio recibiría una buena
cantidad de dinero, clases de actuación y otros beneficios, claro que
aceptamos sin pensarlo.</p>
When I process it with the php code above I get the following result:
Foto artísticaMi esposo invito uno de sus viejos amigos a casa, un hombre muy impresionante, lleg�...
That last word in specific is accented llegó
, other words in the same string and "text thumbnail" such as artística
didn't have the same problem, it seems the accented letter at the end is a problem, I have tried to use some php functions to try to encode/decode the string before using substring
but I have not gotten any results, please if you can somehow guide me to the solution please do it.
Here is the php code behaving the same way in an online editor https://ideone.com/m6OjUN