How to get the last char of a string in PHP?

前端 未结 12 1416
说谎
说谎 2020-12-04 05:24

I need to get the last character of a string. Say I have \"testers\" as input string and I want the result to be \"s\". how can I do that in PHP?

12条回答
  •  情深已故
    2020-12-04 05:58

    Remember, if you have a string which was read as a line from a text file using the fgets() function, you need to use substr($string, -3, 1) so that you get the actual character and not part of the CRLF (Carriage Return Line Feed).

    I don't think the person who asked the question needed this, but for me, I was having trouble getting that last character from a string from a text file so I'm sure others will come across similar problems.

提交回复
热议问题