mar*_*kmb 2 javascript php arrays parsing
我试图通过解析从网站获取信息,我发现这段javascript代码:
var product = {
identifier: '198980',
valid: '1378159199',
fn: 'Entrada para IMAX Barcelona, para cualquier sesión y día',
description: '',
category : [ 'Barcelona','Planes del día','Actividades'],
brand: '',
price: '5.00',
amount: '9.75',
currency: 'EUR',
url: 'http://es.letsbonus.com/ocio/barcelona/entrada-a-imax-port-vell-2013-08-02-198980',
photo: 'http://media5.letsbonus.com/products/198000/198980/13509238959102-0-680x276.jpg'
};
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,这个javascript代码包含网站中某个产品的大量信息,因此解析它会很有趣.我可以看到这不是JSON对象,也不是Javascript数组.
我的问题是:
这是某种类型的Javascript对象吗?如果是这样,在PHP中是否有任何简单的处理方式?我已经能够在我的代码中检索这个特定的字符串.
它是一个JavaScript对象文字.
如果你直接从PHP获取它,你将不得不自己解析它(也许使用正则表达式就足够了).我建议你也查看以下链接: