xernt.com




Xernt helps you find up-to-date answers & allows to take a part in building human knowledge database.
This Post below ↓ is only visible to you.
It is sheduled to delete with all the changelog & comment data attached. You can cancel deletion at any time.
4 weeks left
TIP. Editing item cancels the deletion shedule automatically.
STRING LENGHT PHP, string count, string count php

STRING LENGHT PHP, string count, string count phpEdit

 
 
STRING LENGHT PHP, string count, string count php

strlen();


$text = 'hello world';
echo strlen($text); // 11

?>




Useful function(s) from: php.net/manual/en/function.strlen.php

/**
* return length of a string regardeless of html tags in it
*
* @param string $html
* @return string
*/
function strlen_noHtml($string){
$crs = 0;
$charlen = 0;
$len = strlen($string);
while($crs < $len)
{
$offset = $crs;
$crs = strpos($string, "<", $offset);
if($crs === false)
{
$crs = $len;
$charlen += $crs - $offset;
}
else
{
$charlen += $crs - $offset;
$crs = strpos($string, ">", $crs)+1;
}
}
return $charlen;
}

/**
* return length of a string regarding html tags in it
*
* @param string $html
* @return string
*/
function strlen_Html($string){
$crs = 0;
$charlen = 0;
$len = strlen($string);
while($crs < $len)
{
$scrs = strpos($string, "<", $crs);
if($scrs === false)
{
$crs = $len;
}
else
{
$crs = strpos($string, ">", $scrs)+1;
if($crs === false)
$crs = $len;
$charlen += $crs - $scrs;
}
}
return $charlen;
}
?>

Example:

$text = "

Test 'a' paragraph.

Other text";

echo "strlen without HTML chars:".strlen_noHtml($text);
echo "
";
echo "strlen of HTML chars:".strlen_html($text);
?>

Will output:
strlen without HTML chars:30
strlen of HTML chars:23
Edit
Comment · pm1  · 2 years ago
Please login or create an account to post a comment.
Follow Post
Related Posts
3,298 views


 
 
121 online
About · Blog · Explore · Privacy · Terms · Help  up

These items will be permanently deleted and cannot be recovered. Are you sure?