0

How do I do this?

I use the following code to get position of the first occurrence (case insensitive) of $search within $space.

$word = stripos($space, $search);

However I would like to totally ignore some characters while matching and get the position of similar substrings within the search space. Suppose:

$space = "this is a string saying hello-world";
$search = "hello world";

I would like to have the position of "hello-world" returned even though the string searched was "hello world".

Anyone know how to do this?

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by raphie
0

I think you're needing Regular Expressions methods look into the PHP Manual you might find what you're looking for!

For example:

preg_match('/'.$space.'/g',$search);

or

preg_match('/(hello|world)/g',$search);

This will match all the occurrences in a string that matches whatever is in the $space variable or by the worlds between the parenthesis separated by the column (I don't remember exactly how that symbol is called, sorry!)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.