johnsmith153 Posted January 19, 2011 Share Posted January 19, 2011 I have never understood regular expressions, or spent enough time trying to. I could do with help being able to remove everything before a set value. So "jhfwhfeijhfgeih VALUE wufhehiehriehr" would return "VALUE wufhehiehriehr" Should be easy. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/224999-simple-preg-replace/ Share on other sites More sharing options...
AbraCadaver Posted January 19, 2011 Share Posted January 19, 2011 Try learning them. It is fun and very useful. $new = preg_replace('/.*(VALUE.*)/', '$1', $old); Link to comment https://forums.phpfreaks.com/topic/224999-simple-preg-replace/#findComment-1162113 Share on other sites More sharing options...
Goose Posted January 19, 2011 Share Posted January 19, 2011 This solution isn't using regular expressions, but I think it might be quicker. If you are sure that you will have that pattern you showed above you can do this: $pos = strpos($yourString, ' '); if($pos !== false){ $yourNewString = substr($yourString, $pos + 1); } Link to comment https://forums.phpfreaks.com/topic/224999-simple-preg-replace/#findComment-1162116 Share on other sites More sharing options...
AbraCadaver Posted January 19, 2011 Share Posted January 19, 2011 Yes, or even shorter: $new = strstr($old, 'VALUE'); Link to comment https://forums.phpfreaks.com/topic/224999-simple-preg-replace/#findComment-1162124 Share on other sites More sharing options...
Goose Posted January 19, 2011 Share Posted January 19, 2011 Good call. Link to comment https://forums.phpfreaks.com/topic/224999-simple-preg-replace/#findComment-1162166 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.