在PHP中,我如何从结尾开始用x字符截断字符串? [关闭]

How do I truncate a string thats 120 characters to 100 characters but have the count of the length start from the end of the string? So that the 20 characters are removed from the beginning of the string rather than the end?

Use substr i.e.

$newline = substr($oldline, 20);

or

$newline = substr($oldline, -100);

You could use the substr function

$str = "Hello How are you?"
$str2 = substr($str, 5); // "How are you?"

For first 20 characters

$string = substr($str,20);

Simply use substr in PHP
http://php.net/manual/en/function.substr.php

substr("abcdef", 20); // "abc.." is of course an example string. 
                      // this sets it to position start of 20 from left.

substr()

$shortString = substr($string, 20);

$newString = substr($oldString, -100) will return the last 100 characters of a string (or false if the string is shorter).

Let me suggest to start from the end. If you know already that is going to be 100 chars:

   $string=substr($yourstring,-100);