dongteng0748 2012-11-15 08:11
浏览 13
已采纳

php中php字符串的最后一个字符

In C the last character of a string is always '\0' Is it same for PHP as well? If not, then what's the last character of a string in PHP?

  • 写回答

4条回答 默认 最新

  • douliangbian7323 2012-11-15 08:16
    关注
    for( $i = 0, $len = strlen( $string ); $i < $len; $i++ )
    {
        $char = $string[ $i ];
        // do something with $char
    }
    

    ... is one way to do it.

    Another way, is simply using PHP function str_split() (which creates an array of the individual characters of the string (unless you pass it the second argument $split_length of a different length than the default)):

    foreach( str_split( $string ) as $char )
    {
        // do something with $char
    }
    

    ... etc.

    Edit:

    As an addendum to your comments to your question; use fgetcsv() for parsing csv files.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭