dtcuv8044 2016-02-29 01:43
浏览 344

substr_replace和substr得到最后一个char返回�

I tried:

substr($string, 0, -1);
substr_replace($string ,"",-1);

but get always

and not the last char of my string????

I want to compare strings and the last Char of stringTwo always is missing, so i tried to find equal stings with substr_replace or substr function and deleting the last char.

$stringOne = "house";

$stringTwo = "hous";

it is strange again and again i get �� by using substring and substr_replace... with mb_substr i can delete the �, but how can i check before doing something if i use mb_substr or substr???

  • 写回答

2条回答 默认 最新

  • doulu4413 2016-02-29 01:59
    关注

    To get the last character of a string just use the substr method. The substr parameters are substr(string $string, int $start, [,int $length]).

    This should get the last character:

    echo substr($string, -1, 1);
    

    To compare two strings, where the last character is removed from $stringTwo, you can use the following:

    if($stringTwo == substr($stringOne, 0, -1)){}
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题