I cant remember what to use to return only a specific part of a string. I have a string like this:-
$str = "return(me or not?)";
I want to get the word which is after (. In this example me
will be my result. How can I do this?
I dont think substr is what I am looking for. as substr returns value based on the index you provided. which in this case i dont know the index, it can vary. All I know is that I want to return whatever is after "(" and before the space " ". The index positions will always be different there for i cant use substr(..).
This regular expression should do the trick. Since you didn't provide general rules but only an example it might need further changes though.
preg_match('/\((\S+)/', $input, $matches);
$matches[1]
contains "me" then.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments