Ortix Posted January 12, 2012 Share Posted January 12, 2012 Hi guys, I need to find a way to do the following in this string: {"id":"51","value":["Lorem Ipsum","Lorem Ipsum","new"]} I need to match "id":"51" If that is matched, I want to remove that ENTIRE string. How would I go about doing that? In other words, I run a preg_match or something like that and if "id":"51" is found, i need to remove the entire element in which it is contained. In this case the element is the above mentioned string. Any ideas? Perhaps with RegEx? (I have no clue how to use RegEx) Link to comment https://forums.phpfreaks.com/topic/254844-complex-string-replacement/ Share on other sites More sharing options...
PaulRyan Posted January 12, 2012 Share Posted January 12, 2012 The string you are using is only JSON encode, you can decode it by using json_decode Something like this should work: <?PHP $string = '{"id":"51","value":["Lorem Ipsum","Lorem Ipsum","new"]}'; $decodeStr = json_decode($string,true); if($decodeStr['id'] == 51) { $string = ''; } echo $string; ?> Regards, PaulRyan. Link to comment https://forums.phpfreaks.com/topic/254844-complex-string-replacement/#findComment-1306736 Share on other sites More sharing options...
Ortix Posted January 12, 2012 Author Share Posted January 12, 2012 Worked like a charm! True hero! Link to comment https://forums.phpfreaks.com/topic/254844-complex-string-replacement/#findComment-1307075 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.