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?

Recommended Answers

All 3 Replies

Still waiting...

Member Avatar for diafol

did you check out your last thread on this? You're still waiting... So am I.

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!)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.