doupai1876 2011-03-07 12:04
浏览 37
已采纳

Php str_replace无法正常工作

i've got a long string which is space delimited (read in from a txt file)

Input String:

$value = "TestNumber1  X Chan 1 Wrap Hi (5.0 V) (UNC)    9.860           V        GELE (>= <=) 9.750           10.250          Passed"

What I want to do, and have done succesfully is explode this string into a array using:

$Exploded = explode("  ",$value);

Unfortunatly though, I also want to seperate between the GELE (>= <=) part, and the following number (in this case 9.750), so I thought to make this easy, before I explode the string I'll do:

$value = str_replace("GELE (>= <=) ","GELE (>= <=)  ",$value);

The problem is, for some reason the replace isn't working. It's as if it's not seeing the needle. This is what my exploded string array is giving me after doing the str_replace.

Array ( [0] => TestNumber1 X Chan 1 Wrap Hi (5.0 V) (UNC) [1] => 9.860 [2] => V [3] => GELE (>= <=) 9.750 [4] => 10.250 [5] => Passed [6] => ) 

As you can see, element [3] => GELE (>= <=) 9.750

Is there anything stupid I'm doing here to make my str_replace function not work?

Thanks in advance.

  • 写回答

3条回答 默认 最新

  • duanji8615 2011-03-07 12:06
    关注

    The whitespace after the string may be a tab character rather than spaces.

    Try first replacing tabs \t with spaces.

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

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了