How can I use preg_replace to remove everything after a keyword is matched?
For instance, if the keyword local is matched in the string below,
home/hello/local/flower/stone/...
then return this only,
home/hello
or can I use any php default array function?
Depending on what you want to do, a simple
strpos + strlencould do the trick.http://ideone.com/3OOq8
Be careful, I assumed that you’ll always have your keyword in the String, that might not be the case.
Resources: