0

I have problem with checking if part of string is containing other string but strpos and stripos are not working for me.

The case that I need to check if word pris is containing in string -med prista-

Any suggestions?

2
  • 1
    You mean like this? Commented Dec 15, 2021 at 13:16
  • If strpos isn't working for checking the possible position of a substring in a string, it means you are doing something wrong, and should refer to the manual (and/or post the code that isn't working): php.net/strpos Commented Dec 15, 2021 at 15:20

2 Answers 2

1

Try

$str = '-med prista-';
if (preg_match('/pris/', $str))
    echo 'OK';
else
    echo 'Not';
Sign up to request clarification or add additional context in comments.

Comments

1

In PHP 8 you have a new function called str_contains() created for this purpose:

if (str_contains('-med prista-', 'pris')) {
    echo "Found!";
}

If you are using older PHP versions then you can use mb_strpos (multibyte), or strpos functions like this:

if(mb_strpos('-med prista-', 'pris') === false){
    // not found
} else {
    echo "Found!";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.