简体   繁体   中英

preg_match - Extracting a Value

I am a beginner at php, and have found a need for preg_match. After looking through posts here, this example is still rather beyond. Can someone point me in the right direction.

The list entry is as below.

    {
     "metadata.title": "",
     "metadata.description": "",
     "metadata.keywords": "",
     "metadata.robots": "",
     "metadata.author": "",
     "config.enable_comments": "0",
     "config.primary_category": "311"
    }

How can I extract the value between the "" within primary_category, in this case 311.

Thanks,

Alec

looks like json to me. Use json_decode

Since it seems like JSON, you could use the json_decode function on the string. Assuming that your string is contained on the variable $json_str, you could do as follows:

$str_data = json_decode($json_str, true);

The function will return an associative array and each element can be accessed as follows:

$str_data["config.primary_category"]

returns the data contained on "config.primary_category".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM