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

前端 未结 12 1437
说谎
说谎 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:49

    Siemano, get only php files from selected directory:

    $dir    = '/home/zetdoa/ftp/domeny/MY_DOMAIN/projekty/project';
    $files = scandir($dir, 1);
    
    
    foreach($files as $file){
      $n = substr($file, -3);
      if($n == 'php'){
        echo $file.'
    '; } }

提交回复
热议问题