Reputation: 11
I have this string:
"(data I don't care about) (invariable substring) (data I care about)"
How do I trim all the data I don't care about, knowing the invariable substring?
Upvotes: 1
Views: 990
Reputation: 11
Simplest I've found is:
list(, $data_i_care_about) = explode('(invariable substring)', $all_the_data, 2)
Upvotes: 1
Reputation: 655239
You could get the offset and only take the substring from that offset on:
if (($pos = strpos($str, $substr)) !== false) {
$str = substr($str, $pos);
}
Upvotes: 1
Reputation: 3330
This should suffice:
substr($string, (int)strpos("invariablestring", $string));
But will leave the invariablestring untouched. If you want to remove that string, just add it's length to the value strpos() returned.
Upvotes: 2