Skip to main content
added 318 characters in body
Source Link
KHansen
  • 900
  • 1
  • 6
  • 25

Thanks to @Pakoco I found a solution:

if (preg_match('/^(?i)(?=.*?\b' . $needle . '\b).*/', $haystack) === 1) {
    // do stuff
}

For completion here the regex if the needle has to be at the beginning:

if (preg_match('/^(?i)(' . $needle . '\b).*/', $haystack) === 1) {
    // do stuff
}

And here if the needle has to be at the end:

if (preg_match('/(?i)(\b' . $needle . ')$/', $haystack) === 1) {
    // do stuff
}

Thanks to @Pakoco I found a solution:

if (preg_match('/^(?i)(?=.*?\b' . $needle . '\b).*/', $haystack) === 1) {
    // do stuff
}

Thanks to @Pakoco I found a solution:

if (preg_match('/^(?i)(?=.*?\b' . $needle . '\b).*/', $haystack) === 1) {
    // do stuff
}

For completion here the regex if the needle has to be at the beginning:

if (preg_match('/^(?i)(' . $needle . '\b).*/', $haystack) === 1) {
    // do stuff
}

And here if the needle has to be at the end:

if (preg_match('/(?i)(\b' . $needle . ')$/', $haystack) === 1) {
    // do stuff
}
Source Link
KHansen
  • 900
  • 1
  • 6
  • 25

Thanks to @Pakoco I found a solution:

if (preg_match('/^(?i)(?=.*?\b' . $needle . '\b).*/', $haystack) === 1) {
    // do stuff
}