我从embed.ly一个JSON响应,我得到我的PHP脚本是这样的:PHP - 从字符串中删除HTML的属性在JSON
// jSON URL which should be requested
$json_url = 'http://api.embed.ly/1/oembed?key=hidden&url='.$_POST['url'];
// Initializing curl
$ch = curl_init($json_url);
// Configuring curl options
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json') ,
);
// Setting curl options
curl_setopt_array($ch, $options);
// Getting results
$result = curl_exec($ch); // Getting jSON result string
我的问题是,我想从响应embed.ly嵌在我响应布局,但视频embed.ly-反应包括与& height属性:
{"provider_url": "http://www.youtube.com/", "description": "Markus Eisenrings Stromboli electric car on swiss television broadcast. See www.stromboli.ch for more information.", "title": "Stromboli Electric Car", "url": "http://www.youtube.com/watch?v=TJCZnpHuFS8", "author_name": "hangflug", "height": 360, "thumbnail_width": 480, "width": 640, "html": "<iframe width=\"640\" height=\"360\" src=\"http://www.youtube.com/embed/TJCZnpHuFS8?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>", "author_url": "http://www.youtube.com/user/hangflug", "version": "1.0", "provider_name": "YouTube", "thumbnail_url": "http://i1.ytimg.com/vi/TJCZnpHuFS8/hqdefault.jpg", "type": "video", "thumbnail_height": 360}
我试着删除了所有宽度&从JSON字符串这样的高度属性:
$result = json_encode(preg_replace('/\<(.*?)(width="(.*?)")(.*?)(height="(.*?)")(.*?)\>/i', '<$1$4$7>', json_decode($result)));
但是,这给了我一个PHP错误。
Catchable fatal error: Object of class stdClass could not be converted to string in /Applications/XAMPP/xamppfiles/htdocs/projectname/ajax.php on line 22
任何想法?
什么错误它给? – martriay 2013-02-16 18:54:38
你会得到什么错误? – desbest 2013-02-16 18:58:59
对不起,在 – 2013-02-16 19:00:12