获取2个单词之间的内容

时间:2012-09-23 09:55:26

标签: php

我想获得两个单词(word1word2)之间的内容(文本),例如:

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

所以内容= blablabla Poetry can be divided into several genres, or categories.

但是,有时问题word1word2可以是大写字母或小写字母。另一个问题是结果中仍然会打印word1。它应该打印出来。如何处理这个问题?谢谢你:))

这是代码:

$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 个答案:

答案 0 :(得分:4)

您可以使用stripos代替strpos

  

stripos - 查找第一次出现的位置   字符串中不区分大小写的子字符串