Reputation: 11
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 to use str_replace('Hello', $b.'World', $b)
.
Upvotes: 0
Views: 1506
Reputation: 7881
if (strpos($a, $b) !== false) {
// $b is in $a
} else {
// $b is not in $a
str_replace('Hello', $b . 'World', $b);
}
Upvotes: 1