[英]preg_match - Extracting a Value
我是php的初學者,並且發現需要preg_match。 在這里查看帖子之后,這個例子仍然相當遠。 有人能指出我正確的方向。
列表條目如下。
{
"metadata.title": "",
"metadata.description": "",
"metadata.keywords": "",
"metadata.robots": "",
"metadata.author": "",
"config.enable_comments": "0",
"config.primary_category": "311"
}
如何在primary_category中提取“”之間的值,在本例中為311。
謝謝,
亞歷克
對我來說就像是json。 使用json_decode
由於它看起來像JSON,你可以在字符串上使用json_decode函數。 假設您的字符串包含在變量$ json_str中,您可以執行以下操作:
$str_data = json_decode($json_str, true);
該函數將返回一個關聯數組,並且可以按如下方式訪問每個元素:
$str_data["config.primary_category"]
返回“config.primary_category”中包含的數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.