I’m new to php and am trying to write a regular expression using preg_match to extract the href value that I get from my http get.
The response looks:
{"_links":{"http://a.b.co/documents":{"href":"/docs"}}}
I want to extract only the href value and pass it to my next api… i.e. /docs.
Can anyone please tell me how to extract this?
I’ve been using http://www.solmetra.com/scripts/regex/index.php to test my regex.. and had no luck since last one day 🙁
please any help would be appreciated.
Thanks,
DR
No need for a regex.
Use
json_decode()and then access thehrefproperty.For example:
Note: I’d encourage you to clean up your JSON if possible. Particularly the keys.