douzi1986 2012-09-23 09:55
浏览 64
已采纳

获取2个单词之间的内容

I wanna get the contents (text) between two words(word1 and word2), for example :

word1blablabla Poetry can be divided into several genres, or categories. word2 blablabla

so the contents = blablabla Poetry can be divided into several genres, or categories.

but, the problems sometimes the word1 and word2 can be in upper-case letter or in lower-case letter. And the other problem is the word1 still be printed in the result. It should be printed. How to handle that problem? thank you :)

here's the code :

$file = 'word1 blablabla word1 Poetry can be divided into several genres, or categories. word2 blablabla ';
$word1='word1';
$word2='word2';
$between  = substr($file, strpos($file, $word1), strpos($file, $word2) - strpos($file, $word1));
  • 写回答

1条回答 默认 最新

  • douqin231881 2012-09-23 09:56
    关注

    You can use stripos instead of strpos:

    stripos — Find the position of the first occurrence of a case-insensitive substring in a string

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效