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 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)