Skip to content

Instantly share code, notes, and snippets.

@jagroop
Last active March 1, 2018 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jagroop/928711048f2d2b9d9b96ffa84c16349e to your computer and use it in GitHub Desktop.
Save jagroop/928711048f2d2b9d9b96ffa84c16349e to your computer and use it in GitHub Desktop.
PHP Parse string and Limit 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