MY question is So simple. i have this string:
$main = "this is my main string here that i want to cut it and return here !";
And my key is:
$key = "main";
Now, i want to have this output:
$output = "main string here that i want to cut it and return here !";
I mean i want to have that output , from my main word till end of sentence!
How can i do it with PHP ?
You can use this code.
$main = "this is my main string here that i want to cut it and return here !";
echo strstr($main , 'main');
try this
$str="this is my main string here that i want to cut it and return here !";
echo strstr($str, 'main');
$main = "this is my main string here that i want to cut it and return here !";
$key = "main";
echo substr($main,strpos($main,$key));
Using strpos you can find the first ocurrence of $key in $main:
$main = "this is my main string here that i want to cut it and return here !";
$key = "main";
$x = strpos($main, $key);
$result = substr($main, $x);
echo $result;
Try Below code :
$main="this is my main string here that i want to cut it and return here !";
echo strstr($main, 'main');
strpos
find first position of substring, 'main' in our case. It return 11, put it into $tmp. substr
return part of our string $main
from start to $tmp
position. As result main string here that i want to cut it and return here!
$main = "this is my main string here that i want to cut it and return here !";
$tmp = strpos($main, "main");
echo substr($main, $tmp);