-8

I want check whether particular string is present within string or not. And i want to get position matching.

For Eg:

$actual_string = "red";
$searching_string = "green red yellow";

As we know , above searching string "red" matches with actual string, and position matched is 7th(including space).

$output = 7;//red matched at 7th position

Is is possible to get above requirement? Please help

sshashank124
  • 31,495
  • 9
  • 67
  • 76

1 Answers1

2

Try with strpos like

echo strpos($searching_string, $actual_string);

But it will consider the string position that starts from 0.So you need to +1 for the position to get the correct position.

GautamD31
  • 28,552
  • 10
  • 64
  • 85
  • Thanks for your answer, it does't worked in my case. Because above returns only full word is matched.In my case,any searching string which matches within actual string. Best eg: $actual_string = "red/blue/green"; $searching_string = "green black"; – Thangapandiyan M D Apr 17 '14 at 13:41
  • @ThangapandiyanMD, then your question is not clear enough. This answer is correct for what you asked. Your comment here only confuses matters. – ChrisGPT was on strike Apr 17 '14 at 14:37