2012-10-27 59 views
0

我是一名初學者,並且發現需要preg_match。在查看帖子後,這個例子還是比較難。有人能指引我走向正確的方向嗎?preg_match - 提取值

列表條目如下。

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

我怎樣才能提取 「」 primary_category內,在這種情況下,311

感謝之間的值,

亞歷克

回答

1

看起來像JSON我。使用json_decode

+0

echo json_decode($ text) - > {'config.primary_category'}; –

1

由於它看起來像JSON,你可以在字符串上使用json_decode函數。假設你的字符串包含的變量$ json_str,你可以做如下:

$str_data = json_decode($json_str, true); 

該函數會返回一個關聯數組,每個元素可以如下訪問:

$str_data["config.primary_category"] 

返回包含在「config.primary_category」中的數據。