Reputation: 584
$string = 'hello world php is a bla bla..';
How to keep 'hello world php', by finding if the string contains any 'is', and then remove all the characters after it?
I can't use substr because the occurrence of 'is' is not consistent, also it may be repeatable. How to catch the first one?
Upvotes: 0
Views: 98
Reputation: 7791
You can use explode:
<?php
$string = 'hello world php is a bla bla..';
$string = explode(' is ', $string);
echo $string[0];
?>
Read more at:
Upvotes: 1
Reputation: 1545
try like this,
$string = 'hello world php is a bla bla..';
$str= substr($string, 0, strpos($string, "is"));
also you can use preg_replace,
$str = preg_replace('/ is.*/', '', $string );
Upvotes: 1