PHP/String/strrev
Содержание
Reversing a string by byte
<?php
print strrev("This is not a palindrome.");
?>
Reversing Strings
<?php
$astring = "Hello World";
echo strrev ($astring);
?>
Reversing Strings: string strrev ( string string )
<?php
$astring = "Hello World";
echo strrev ($astring);
?>
Truncating Text on Word Boundaries
<?php
function truncate_text_nicely($string, $max, $moretext) {
if (strlen($string) > $max) {
$max -= strlen($moretext);
$string = strrev(strstr(strrev(substr($string, 0, $max)), " "));
$string .= $moretext;
}
return $string;
}
$str = "This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.";
$values = truncate_text_nicely($str, 20, "...");
echo "<pre>{$values}</pre>";
?>