开发者

How to check the sub string is exists or not in main string

Is there any way to check the sub string is exists in main string or not. If exits, no need any another action. If not exists, I want to add some another string to main string.

For an example:

$a = 'Hello world';
$b = 'Hello';

I want to check the $b is exists in $a or not. If exists, i am sending that variable to database. If not exists, I want t开发者_如何转开发o use str_replace('Hello', $b.'World', $b).


if (strpos($a, $b) !== false) {
    // $b is in $a
} else {
    // $b is not in $a
    str_replace('Hello', $b . 'World', $b);
}


strpos().

It returns FALSE if the substring is not found.


You are looking for strpos function

remember to use === instead of ==

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜