需要得到部分从字符串在php与正则表达式或其他东西


Need to get part from string in php with regex or something else

访问http://www.draugiem.lv/bkventspils/js/fans?count=0时返回了这个字符串

D.w({"container":"pagescontainer","width":240,"page":{"name":"BK Ventspils","about":"Basketbola Klubs '"Ventspils'"","url":"http:'/'/www.draugiem.lv'/bkventspils","image":"http:'/'/i7.ifrype.com'/business'/001'/547'/v1319550676'/i_13001547.jpg","totalfans":"557"},"fans":[]});

我需要得到"totalfans"计数从这个字符串在php。我试图做它与file_get_contents,然后json_decode像我通常会做,但它不与此字符串工作。我哪里做错了?可能有一个正则表达式来得到这部分,但我不理解正则表达式,所以如果你做请帮助我。

这里有两种可能的解决方案。

1。JSON: 只要去掉开头的D.w(和结尾的);,就可以得到一个包含有效JSON的字符串。

2。RegEx:搜索模式"totalfans":"('d+)"就可以了。