Mancent Posted October 8, 2011 Share Posted October 8, 2011 Warning: SimpleXMLElement::addChild() [simplexmlelement.addchild]: unterminated entity reference limit=50&method=GET&access_token=AAACd5Mcn7VQBAKaupEZCocujRuoBzzWeZCj945ZApHEsv5BZAxZCJfS62cSSz4txlZBUZAec03GcjpHdk0NTotnglt2ZB41GzzeYl8xqIZBmsvlS6UZAoHZB1A4&offset=50 in /home/content/71/8432771/html/facebook/get/friends.php on line 62 <?php /** * Copyright 2011 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain * a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ require '../../src/facebook.php'; // Create our Application instance (replace this with your appId and secret). $facebook = new Facebook(array( 'appId' => 'APPID', 'secret' => 'SECRET', )); // Get User ID $user = $facebook->getUser(); // We may or may not have this data based on whether the user is logged in. // // If we have a $user id here, it means we know the user is logged into // Facebook, but we don't know if the access token is valid. An access // token is invalid if the user logged out of Facebook. if ($user) { try { // Proceed knowing you have a logged in user who's authenticated. $user_profile = $facebook->api('/me/friends?fields=id,name,first_name,last_name,picture&limit=50'); } catch (FacebookApiException $e) { error_log($e); $user = null; } } // Login or logout url will be needed depending on current user state. if ($user) { $logoutUrl = $facebook->getLogoutUrl(); } else { $loginUrl = $facebook->getLoginUrl(); } $profile = array ($user_profile); $xml = new SimpleXMLElement('<root/>'); arrayToXML( $xml, $profile ); echo $xml->asXML(); function arrayToXML( SimpleXMLElement &$xml, $array ) { foreach( $array as $name => $value ) { if( !is_array($value) ) $xml->addChild( $name, $value ); else { $child = $xml->addChild( $name ); <----------------------------------------------LINE 64 arrayToXML( $child, $value ); } } } ?> Here is the array { "data": [ { "name": "Pauline Latty", "id": "312293" }, { "name": "Noah Ethan Schinasi", "id": "55101245" }, { "name": "Luis Guerrero", "id": "194803212" }, { "name": "Nakia Johnson", "id": "500350828" }, { "name": "Bethany Vallerie", "id": "502062429" }, { "name": "Caroline Franks", "id": "505331027" }, { "name": "Andrew Shivers", "id": "505749817" }, { "name": "Sandra G Garcia", "id": "508006303" }, { "name": "Catherine Davis", "id": "511006416" }, { "name": "Marc Watson", "id": "511201074" }, { "name": "Laura Clarke", "id": "513653820" }, { "name": "Amanda Rice", "id": "514062403" }, { "name": "Scott Alan Buss", "id": "514197867" }, { "name": "Evangelist Josephus", "id": "515837621" }, { "name": "Chet Fontenot", "id": "516199085" }, { "name": "Sharon Howard", "id": "516580144" }, { "name": "Chatt Franco", "id": "517211511" }, { "name": "Lydgia Vanessa Staples", "id": "518094760" }, { "name": "Corry Bell", "id": "521043483" }, { "name": "Lessie Tyson", "id": "521855454" }, { "name": "Jawahar Peter", "id": "523159934" }, { "name": "Sheena Shiko", "id": "523461577" }, { "name": "Pat Larry Thomas", "id": "523555768" }, { "name": "Oyenuga Kunle Johnson Matthew", "id": "524263978" }, { "name": "Angela Whitten", "id": "524631356" } ], "paging": { "next": "https://graph.facebook.com/me/friends?limit=25&access_token=2227470867|2.AQAMMvJya05xkLhR.3600.1318057200.0-100001957015772|IUAhNlekyalf7sxy-OjdJd7KCwo&offset=25" } } its that paging, I can not seem to get that to work yet. Quote Link to comment https://forums.phpfreaks.com/topic/248674-can-any-one-help-me-solve-this-problem/ Share on other sites More sharing options...
Mancent Posted October 8, 2011 Author Share Posted October 8, 2011 Im sorry I am very new with arrays But I am interested in learning on this one. I think once I see the fix I will understand it, I know its something simple i just can not find what i am looking for. Quote Link to comment https://forums.phpfreaks.com/topic/248674-can-any-one-help-me-solve-this-problem/#findComment-1277156 Share on other sites More sharing options...
Mancent Posted October 8, 2011 Author Share Posted October 8, 2011 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/248674-can-any-one-help-me-solve-this-problem/#findComment-1277294 Share on other sites More sharing options...
trq Posted October 8, 2011 Share Posted October 8, 2011 The object you are getting back is NOT an array. It's json. See json_decode to turn it into an array. Quote Link to comment https://forums.phpfreaks.com/topic/248674-can-any-one-help-me-solve-this-problem/#findComment-1277312 Share on other sites More sharing options...
Mancent Posted October 9, 2011 Author Share Posted October 9, 2011 Any example: You can give,, the array has json, and I am converting it to xml, so the file product would be a xml, How can I do that? Could you show me? Quote Link to comment https://forums.phpfreaks.com/topic/248674-can-any-one-help-me-solve-this-problem/#findComment-1277324 Share on other sites More sharing options...
jcbones Posted October 9, 2011 Share Posted October 9, 2011 You need to encode the string before sending it to simpleXML. The question mark (?) is what is causing it to barf. I would suggest the work around. //instead of: $xml->addchild('element',$str); //do $xml->element = $str; Quote Link to comment https://forums.phpfreaks.com/topic/248674-can-any-one-help-me-solve-this-problem/#findComment-1277333 Share on other sites More sharing options...
Mancent Posted October 9, 2011 Author Share Posted October 9, 2011 Thank you guys you have been a really big help But however i have not yet had any luck getting it to work, more errors. so my mind just is not getting it yet! Quote Link to comment https://forums.phpfreaks.com/topic/248674-can-any-one-help-me-solve-this-problem/#findComment-1277572 Share on other sites More sharing options...
jcbones Posted October 10, 2011 Share Posted October 10, 2011 You need to change the amperstand (&) to & You can do this with str_replace; Quote Link to comment https://forums.phpfreaks.com/topic/248674-can-any-one-help-me-solve-this-problem/#findComment-1277604 Share on other sites More sharing options...
Mancent Posted October 10, 2011 Author Share Posted October 10, 2011 { //$xml->addChild( $name, $value ); $xml->$name = $value; } Got it! That works perfect. Your awesome jcbones Quote Link to comment https://forums.phpfreaks.com/topic/248674-can-any-one-help-me-solve-this-problem/#findComment-1277640 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.