如何在PHP中的特定字符串后检查指定的字符串是否发生?

时间:2012-11-05 07:36:58

标签: php string

我有一个头衔。我想检查指定的字符串是否出现在php中特定字符串之后/之前。

为前,

Title = Director, Employee Representative

我想检查单词Employee是否出现在标题中Representative之后/之前。 如果标题包含Representative,请检查该字词之前/旁边的字词是Employee

怎么做?

1 个答案:

答案 0 :(得分:1)

一种方法是将其转换为数组,例如:explode(" ","Employee Representative")

array(
 0 => Employee
 1 => Representative
)

然后你可以得到你正在寻找的单词的键(在这种情况下为1)并递增或递减它以查看它之前或之后的单词。