dongluanan7163 2013-09-19 16:29
浏览 28

从特定关键字或位置遍历php

I want to find the string from

$str = "Hello this is dummy.test. in this string  
any character, any special character can appear. it is not a fixed type 
text and predefined. this string will not read manually check by the 
Programmer.Sorry for the bad English.";

my algo is fixed because some kind of problem. First I want to find the position of test keyword then want to go back from test to dummy keyword to find position of dummy keyword .

I also searched and also use the internet but no any function found in PHP which can traverse back in this way.

I also test strrpos() but not relevant and required result. Any solution please.

Output needed : dummy.test

Algo : find first right (test) and then right to left (dummy) only. not first right (test) and then from starting to left (dummy) .

  • 写回答

2条回答 默认 最新

  • dtj2ww9500 2013-09-19 16:35
    关注

    strrpos Would be the right way. If I understand you correctly, this should work, using the offset parameter:

    $test = strrpos($str, 'test');
    $dummy = strrpos($str, 'dummy', $test);
    

    This will find the last "dummy" that occurs before the last "test".

    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源