简体   繁体   中英

“substr” value of TinyMCE in php, HTML tags stripping. Design get distorted due to substring shown in grid

Whenever a html content entered from TinyMCE or other editor, shown in grid with short content, the design get distorted due to or etc. as applied substr($strin, 0, 100).

for example:

$str = '<div class="contnt"><p><span>Operating system, memory expandable up to 32GB and dual SIM</span></p></div><div class="clear">The Seagate Expansion portable drive is compact and perfect for on-the-go. Instantly add more storage space to your computer and take large files with you when you travel. Setup is simple and straightforward; simply connect a single USB cable and you are ready to go. The drive is powered from the USB cable, so there is no need for an external power supply. Plus, it is automatically recognized by the Windows operating system, so there is no software to install and nothing to configure. Saving files is easy—simply drag-and-drop. Take advantage of the fast data transfer speeds with the USB 3.0 interface by connecting to a SuperSpeed USB 3.0 port. USB 3.0 is backwards compatible with USB 2.0 for additional system compatibility</div><div>Digital photos, video and music files can tax your computer's storage, causing performance to decline as its internal hard drive fills to capacity. The Expansion portable hard drive helps remedy this situation by enabling you to free up storage space on your computer's hard drive.</div>';

When dev want to show 100 character as in php

echo substr($str, 0, 100);

The design get distorted.

The Problem may be resolved with the following code

//tinymce sub-string in grid view list
$str = strip_tags(html_entity_decode($str));
$lim = 100;
if (mb_strlen($str,'UTF-8')>$lim)
{
   $str = mb_substr($str, 0, $lim-3, 'UTF-8').'..';
}
echo $str;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM