बस का विस्तार करने के Gurmbo जवाब है। Mb_substr का उपयोग करने से आपकी समस्या हल हो जाएगी, लेकिन फिर भी जब आप यात्रा करते समय विशेष पात्र अंत में आते हैं, तो यह अभी भी कुछ विशेष वर्ण दिखाता है। तो जब मैंने कुछ शोध किया, तो इस समस्या को हल करने के लिए वर्डप्रेस wp_html_excerpt विधि।
wp_html_excerpt विधि लाइन के अंत से उन विशेष पात्रों को हटा देता है।
यहां WordPress से source code है।
/**
* Safely extracts not more than the first $count characters from html string.
*
* UTF-8, tags and entities safe prefix extraction. Entities inside will *NOT*
* be counted as one character. For example & will be counted as 4, < as
* 3, etc.
*
* @since 2.5.0
*
* @param string $str String to get the excerpt from.
* @param int $count Maximum number of characters to take.
* @param string $more Optional. What to append if $str needs to be trimmed. Defaults to empty string.
* @return string The excerpt.
*/
function wp_html_excerpt($str, $count, $more = null) {
if (null === $more)
$more = '';
$str = wp_strip_all_tags($str, true);
$excerpt = mb_substr($str, 0, $count);
// remove part of an entity at the end
$excerpt = preg_replace('/&[^;\s]{0,6}$/', '', $excerpt);
if ($str != $excerpt)
$excerpt = trim($excerpt) . $more;
return $excerpt;
}
क्या आप पहले और बाद में स्ट्रिंग का उदाहरण प्रदान कर सकते हैं? – robertbasic