Last active
March 1, 2018 05:40
-
-
Save jagroop/928711048f2d2b9d9b96ffa84c16349e to your computer and use it in GitHub Desktop.
PHP Parse string and Limit Characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function parseString($text, $limit = 100, $end = '') | |
{ | |
$text = preg_replace("/[\r\n]+/", "\n", $text); | |
$value = stripslashes(preg_replace("/\s+/", ' ', $text)); | |
if (mb_strlen($value) <= $limit) { | |
return $value; | |
} | |
return rtrim(mb_substr($value, 0, $limit, 'UTF-8')) . $end; | |
} | |
$text = "Once you have linked at least one Family member, Proceed to below steps. Also make sure you have disabled add blocker in your browser."; | |
echo parseString($text, $limit = 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment