I have got XML response from curl and trying to search some tag value but I am failing. Kindly somebody help me
Please bare as I am new to the PHP
<?php
$DynamicValue = 'KWI';
$url='https://www.example.com/_api/web/lists/getbytitle(\'Stations\')/items?$select=OfficeId&$filter='.urlencode("CityCode eq '" . $DynamicValue . "'");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/xml"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$XML = new SimpleXMLElement($result);
foreach($XML->entry as $value)
{
echo $value->OfficeId
}
Output:
<?xml version="1.0" encoding="utf-8"?><feed xml:base="https://www.example.com/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"><id>a9f073a2-387e-4ac5-81b9-16b3ae81dba3</id><title /><updated>2017-03-20T08:15:47Z</updated><entry m:etag=""61""><id>Web/Lists(guid'5344b09b-d3f7-44ec-bd52-a8f5a99f23f9')/Items(23)</id><category term="SP.Data.StationsListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/Lists(guid'5344b09b-d3f7-44ec-bd52-a8f5a99f23f9')/Items(23)" /><title /><updated>2017-03-20T08:15:47Z</updated><author><name /></author><content type="application/xml"><m:properties><d:OfficeId>KWIKU08AA</d:OfficeId></m:properties></content></entry></feed>
Hope this will work.
$string='<?xml version="1.0" encoding="utf-8"?><feed xml:base="https://www.example.com/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"><id>a9f073a2-387e-4ac5-81b9-16b3ae81dba3</id><title /><updated>2017-03-20T08:15:47Z</updated><entry m:etag=""61""><id>Web/Lists(guid\'5344b09b-d3f7-44ec-bd52-a8f5a99f23f9\')/Items(23)</id><category term="SP.Data.StationsListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/Lists(guid\'5344b09b-d3f7-44ec-bd52-a8f5a99f23f9\')/Items(23)" /><title /><updated>2017-03-20T08:15:47Z</updated><author><name /></author><content type="application/xml"><m:properties><d:OfficeId>KWIKU08AA</d:OfficeId></m:properties></content></entry></feed>';
echo explode("</d:OfficeId>",explode("<d:OfficeId>", $string)[1])[0];
PHP Code demo
Related
I am sending the Xml request and getting the response using the CURL request function. If i send the static value i got the response But if i send the dynamic values using PHP file the response not able to get it. May i know where i mistake
Included the 2 codes
<?xml version="1.0" encoding="UTF-8"?>
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<serve xmlns="http://schemas.cordys.com/gateway/Provider">
<SessionDoc xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.cordys.com/gateway/Provider">
<Session>
<SessionData xmlns="XXXX">
<Index>1</Index>
<InitTime>Thu, 05 Oct 17 15:55:44 +0530</InitTime>
<UserName>XXXXX</UserName>
<Password>XXXXX</Password>
<OrderNo>NA</OrderNo>
<QuoteNo>NA</QuoteNo>
<Route>INT</Route>
<Contract>XXX</Contract>
<Channel>XXX</Channel>
<TransactionType>Quote</TransactionType>
<TransactionStatus>Fresh</TransactionStatus>
<ID>XXXXXX</ID>
<UserAgentID>XXXX</UserAgentID>
<Source>XXXX</Source>
<IsCCUser>N</IsCCUser>
</SessionData>
<tns:Vehicle xmlns:tns="XXXXX">
<tns:TypeOfBusiness>TR</tns:TypeOfBusiness>
<tns:AccessoryInsured>N</tns:AccessoryInsured>
<tns:AccessoryValue>0</tns:AccessoryValue>
<tns:AntiTheftDevice>N</tns:AntiTheftDevice>
<tns:BiFuelKit>
<tns:IsBiFuelKit>N</tns:IsBiFuelKit>
<tns:BiFuelKitValue>0</tns:BiFuelKitValue>
<tns:ExternallyFitted>N</tns:ExternallyFitted>
</tns:BiFuelKit>
<tns:DateOfRegistration></tns:DateOfRegistration>
<tns:RiskType>FTW</tns:RiskType>
<tns:Make>HONDA MOTORS</tns:Make>
<tns:Model>ACTIVA</tns:Model>
<tns:FuelType>P</tns:FuelType>
<tns:Variant>3G</tns:Variant>
<tns:IDV>20202</tns:IDV>
<tns:EngineNo></tns:EngineNo>
<tns:ChasisNo></tns:ChasisNo>
<tns:DriveExperiance />
<tns:NoOfDrivers />
<tns:ParkingType />
<tns:AnnualMileage />
<tns:YoungestDriverAge />
<tns:PaidDriver />
<tns:VehicleAge>4</tns:VehicleAge>
<tns:CC>109</tns:CC>
<tns:PlaceOfRegistration>Mumbai Navi Mumbai</tns:PlaceOfRegistration>
<tns:SeatingCapacity>2</tns:SeatingCapacity>
<tns:VehicleExtraTag01 />
<tns:RegistrationNo></tns:RegistrationNo>
<tns:ExShowroomPrice>51800</tns:ExShowroomPrice>
<tns:DateOfManufacture>2014</tns:DateOfManufacture>
</tns:Vehicle>
<tns:Quote xmlns:tns="XXXXXX">
<PolicyTenure>1</PolicyTenure>
<tns:ExistingPolicy>
<tns:Claims>0</tns:Claims>
<tns:PolicyType>Comprehensive</tns:PolicyType>
<tns:EndDate></tns:EndDate>
<tns:NCB>0</tns:NCB>
<tns:PolicyNo></tns:PolicyNo>
<tns:InsuranceCompany></tns:InsuranceCompany>
</tns:ExistingPolicy>
<tns:PolicyStartDate>2017-10-06T00:00:00.000</tns:PolicyStartDate>
<tns:Deductible>0</tns:Deductible>
<tns:PAFamilySI>100000</tns:PAFamilySI>
<tns:AgentNumber>2C000002</tns:AgentNumber>
<tns:DealerId>619</tns:DealerId>
<tns:Premium>
<tns:Discount />
</tns:Premium>
<tns:SelectedCovers>
<tns:CarDamageSelected>true</tns:CarDamageSelected>
<tns:TPLiabilitySelected>true</tns:TPLiabilitySelected>
<tns:PADriverSelected>true</tns:PADriverSelected>
<tns:ZeroDepriciationSelected>false</tns:ZeroDepriciationSelected>
<tns:RoadsideAssistanceSelected>false</tns:RoadsideAssistanceSelected>
<tns:InvoicePriceSelected>false</tns:InvoicePriceSelected>
<tns:InvoicePriceCoverAmount />
<tns:PAFamilyPremiumSelected>false</tns:PAFamilyPremiumSelected>
<tns:HospitalCashSelected>false</tns:HospitalCashSelected>
<tns:MedicalExpensesSelected>false</tns:MedicalExpensesSelected>
<tns:AmbulanceChargesSelected>false</tns:AmbulanceChargesSelected>
<tns:CosumableCoverSelected>false</tns:CosumableCoverSelected>
<tns:HydrostaticLockSelected>false</tns:HydrostaticLockSelected>
<tns:KeyReplacementSelected>false</tns:KeyReplacementSelected>
<tns:NoClaimBonusSameSlabSelected>false</tns:NoClaimBonusSameSlabSelected>
<tns:EngineGearBoxProtectionSelected>false</tns:EngineGearBoxProtectionSelected>
</tns:SelectedCovers>
<tns:PolicyEndDate>2018-10-05T23:59:59.000</tns:PolicyEndDate>
</tns:Quote>
<tns:Client xmlns:tns="XXX">
<tns:ClientType>Individual</tns:ClientType>
<tns:CltDOB></tns:CltDOB>
<tns:FinancierDetails>
<tns:IsFinanced>0</tns:IsFinanced>
<tns:InstitutionName></tns:InstitutionName>
<tns:InstitutionCity></tns:InstitutionCity>
</tns:FinancierDetails>
<tns:GivName>BharatiTwo1507199144</tns:GivName>
<tns:ClientExtraTag01>MAHARASHTRA</tns:ClientExtraTag01>
<tns:CityOfResidence>Mumbai Navi Mumbai</tns:CityOfResidence>
<tns:EmailID>dfgkgj#KJhj.com</tns:EmailID>
<tns:MobileNo>9865325896</tns:MobileNo>
<tns:LandLineNo></tns:LandLineNo>
<tns:SurName></tns:SurName>
<tns:CltSex></tns:CltSex>
<tns:Marryd></tns:Marryd>
<tns:Occupation></tns:Occupation>
<tns:CltAddr01></tns:CltAddr01>
<tns:CltAddr02></tns:CltAddr02>
<tns:CltAddr03></tns:CltAddr03>
<tns:City></tns:City>
<tns:State></tns:State>
<tns:PinCode></tns:PinCode>
<tns:Nominee>
<tns:Name></tns:Name>
<tns:Age></tns:Age>
<tns:Relationship></tns:Relationship>
<tns:Appointee></tns:Appointee>
<tns:AppointeeRelation></tns:AppointeeRelation>
</tns:Nominee>
<tns:RegistrationZone>B</tns:RegistrationZone>
<GstinNo>GSTinNO</GstinNo>
</tns:Client>
<Payment>
<PaymentMode />
<PaymentType />
<TxnReferenceNo />
<TxnAmount />
<TxnDate />
<BankCode />
<InstrumentAmount />
</Payment>
</Session>
</SessionDoc>
</serve>
</SOAP:Body>
</SOAP:Envelope>';
$headers = array(
"Content-type: application/xml",
"Content-length: " . strlen($xml),
"Connection: close",
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
echo "<pre>";
echo $data = curl_exec($ch); exit;
this is code for Dynamic generation using PHP Values which we passed
<?xml version="1.0" encoding="UTF-8"?>
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<serve xmlns="http://schemas.cordys.com/gateway/Provider">
<SessionDoc xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.cordys.com/gateway/Provider">
<Session>
<SessionData xmlns="XXX">
<Index>'.$stage.'</Index>
<InitTime>'.$current_date.'</InitTime>
<UserName>XXXXX</UserName>
<Password>XXXX</Password>
<OrderNo>'.$order_no.'</OrderNo>
<QuoteNo>'.$quote_no.'</QuoteNo>
<Route>INT</Route>
<Contract>MTR</Contract>
<Channel>XXXX</Channel>
<TransactionType>Quote</TransactionType>
<TransactionStatus>Fresh</TransactionStatus>
<ID>XXXXX</ID>
<UserAgentID>2C000002</UserAgentID>
<Source>2C000002</Source>
<IsCCUser>N</IsCCUser>
</SessionData>
<tns:Vehicle xmlns:tns="XXX">
<tns:TypeOfBusiness>'.$bis_type.'</tns:TypeOfBusiness>
<tns:AccessoryInsured>'.$access_ins.'</tns:AccessoryInsured>
<tns:AccessoryValue>'.$access_val.'</tns:AccessoryValue>
<tns:AntiTheftDevice>'.$anti_thfdev.'</tns:AntiTheftDevice>
<tns:BiFuelKit>
<tns:IsBiFuelKit>'.$fuel_kit.'</tns:IsBiFuelKit>
<tns:BiFuelKitValue>'.$fuel_kit_val.'</tns:BiFuelKitValue>
<tns:ExternallyFitted>'.$ext_fit.'</tns:ExternallyFitted>
</tns:BiFuelKit>
<tns:DateOfRegistration>'.$veh_reg_date.'</tns:DateOfRegistration>
<tns:RiskType>'.$risktype.'</tns:RiskType>
<tns:Make>'.$make.'</tns:Make>
<tns:Model>'.$model.'</tns:Model>
<tns:FuelType>'.$fuel_type.'</tns:FuelType>
<tns:Variant>'.$variant.'</tns:Variant>
<tns:IDV>'.$idv.'</tns:IDV>
<tns:EngineNo>'.$engine_no.'</tns:EngineNo>
<tns:ChasisNo>'.$chasis_no.'</tns:ChasisNo>
<tns:DriveExperiance />
<tns:NoOfDrivers />
<tns:ParkingType />
<tns:AnnualMileage />
<tns:YoungestDriverAge />
<tns:PaidDriver />
<tns:VehicleAge>'.$veh_age.'</tns:VehicleAge>
<tns:CC>'.$cc.'</tns:CC>
<tns:PlaceOfRegistration>'.$place_reg.'</tns:PlaceOfRegistration>
<tns:SeatingCapacity>'.$seating.'</tns:SeatingCapacity>
<tns:VehicleExtraTag01 />
<tns:RegistrationNo>'.$veh_number.'</tns:RegistrationNo>
<tns:ExShowroomPrice>'.$x_shw_prc.'</tns:ExShowroomPrice>
<tns:DateOfManufacture>'.$mnf_year.'</tns:DateOfManufacture>
</tns:Vehicle>
<tns:Quote xmlns:tns="XXXX">
<PolicyTenure>'.$policy_tenure.'</PolicyTenure>
<tns:ExistingPolicy>
<tns:Claims>0</tns:Claims>
<tns:PolicyType>Comprehensive</tns:PolicyType>
<tns:EndDate>'.$ext_policy_enddate.'</tns:EndDate>
<tns:NCB>'.$ncb_val.'</tns:NCB>
<tns:PolicyNo>'.$policy_no.'</tns:PolicyNo>
<tns:InsuranceCompany>'.$ins_cmp.'</tns:InsuranceCompany>
</tns:ExistingPolicy>
<tns:PolicyStartDate>'.$policy_stdate.'</tns:PolicyStartDate>
<tns:Deductible>'.$deductable.'</tns:Deductible>
<tns:PAFamilySI>100000</tns:PAFamilySI>
<tns:AgentNumber>2C000002</tns:AgentNumber>
<tns:DealerId>619</tns:DealerId>
<tns:Premium>
<tns:Discount />
</tns:Premium>
<tns:SelectedCovers>
<tns:CarDamageSelected>true</tns:CarDamageSelected>
<tns:TPLiabilitySelected>true</tns:TPLiabilitySelected>
<tns:PADriverSelected>true</tns:PADriverSelected>
<tns:ZeroDepriciationSelected>'.$addons_list['DEPC'].'</tns:ZeroDepriciationSelected>
<tns:RoadsideAssistanceSelected>'.$addons_list['RSAC'].'</tns:RoadsideAssistanceSelected>
<tns:InvoicePriceSelected>'.$addons_list['INPC'].'</tns:InvoicePriceSelected>
<tns:InvoicePriceCoverAmount />
<tns:PAFamilyPremiumSelected>'.$addons_list['PAFamily'].'</tns:PAFamilyPremiumSelected>
<tns:HospitalCashSelected>'.$addons_list['HOSP'].'</tns:HospitalCashSelected>
<tns:MedicalExpensesSelected>'.$addons_list['MEDI'].'</tns:MedicalExpensesSelected>
<tns:AmbulanceChargesSelected>'.$addons_list['AMBC'].'</tns:AmbulanceChargesSelected>
<tns:CosumableCoverSelected>'.$addons_list['CONC'].'</tns:CosumableCoverSelected>
<tns:HydrostaticLockSelected>'.$addons_list['HYLC'].'</tns:HydrostaticLockSelected>
<tns:KeyReplacementSelected>'.$addons_list['KEYC'].'</tns:KeyReplacementSelected>
<tns:NoClaimBonusSameSlabSelected>'.$addons_list['NCBS'].'</tns:NoClaimBonusSameSlabSelected>
<tns:EngineGearBoxProtectionSelected>'.$addons_list['EGBP'].'</tns:EngineGearBoxProtectionSelected>
</tns:SelectedCovers>
<tns:PolicyEndDate>'.$policy_endate.'</tns:PolicyEndDate>
</tns:Quote>
<tns:Client xmlns:tns="XXXX">
<tns:ClientType>Individual</tns:ClientType>
<tns:CltDOB>'.$clnt_dob.'</tns:CltDOB>
<tns:FinancierDetails>
<tns:IsFinanced>'.$is_fin.'</tns:IsFinanced>
<tns:InstitutionName>'.$fin_name.'</tns:InstitutionName>
<tns:InstitutionCity>'.$fin_city.'</tns:InstitutionCity>
</tns:FinancierDetails>
<tns:GivName>'.$first_name.'</tns:GivName>
<tns:ClientExtraTag01>'.$reg_state.'</tns:ClientExtraTag01>
<tns:CityOfResidence>'.$rto.'</tns:CityOfResidence>
<tns:EmailID>'.$email_id.'</tns:EmailID>
<tns:MobileNo>'.$mobile_no.'</tns:MobileNo>
<tns:LandLineNo>'.$emg_cnt_no.'</tns:LandLineNo>
<tns:SurName>'.$last_name.'</tns:SurName>
<tns:CltSex>'.$gender.'</tns:CltSex>
<tns:Marryd>'.$martial_status.'</tns:Marryd>
<tns:Occupation>'.$occup.'</tns:Occupation>
<tns:CltAddr01>'.$addr1.'</tns:CltAddr01>
<tns:CltAddr02>'.$addr2.'</tns:CltAddr02>
<tns:CltAddr03>'.$landmark.'</tns:CltAddr03>
<tns:City>'.$city.'</tns:City>
<tns:State>'.$state.'</tns:State>
<tns:PinCode>'.$pincode.'</tns:PinCode>
<tns:Nominee>
<tns:Name>'.$nom_name.'</tns:Name>
<tns:Age>'.$nom_age.'</tns:Age>
<tns:Relationship>'.$nom_rel.'</tns:Relationship>
<tns:Appointee>'.$nom_apnt.'</tns:Appointee>
<tns:AppointeeRelation>'.$nom_apnt_rel.'</tns:AppointeeRelation>
</tns:Nominee>
<tns:RegistrationZone>'.$reg_zone.'</tns:RegistrationZone>
<GstinNo></GstinNo>
</tns:Client>
<Payment>
<PaymentMode />
<PaymentType />
<TxnReferenceNo />
<TxnAmount />
<TxnDate />
<BankCode />
<InstrumentAmount />
</Payment>
</Session>
</SessionDoc>
</serve>
</SOAP:Body>
</SOAP:Envelope>';
$headers = array(
"Content-type: application/xml",
"Content-length: " . strlen($xml),
"Connection: close",
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
Where i did wrong here. Please clear me
I am trying to make an RSS feed which feeds live data from a remote XML file provided to me for promoting a webcam network.
I want to run a feed within my official website. My problem is, I want to output the data into an RSS feed. I am not too familiar with RSS and php so there is a lot of guess work going on.
Here is the code I have so far which will not work, it incorporates php to retrieve the xml data. Also I am unsure as to what filename/type I save this as? XML or php? Both don't seem to work.
<?php
$curlData = '<?xml version="1.0" encoding="UTF-8"?>
<SMLQuery>
<Options MaxResults="20"/>
<AvailablePerformers Exact="false" PageNum="1" CountTotalResults="true">
<Include>
<Country/>
<Headline/>
<Descriptions></Descriptions>
<Rating/>
<Age/>
<Gender/>
<Media>biopic</Media>
<FreeChatSort/>
<PerformanceSort/>
</Include>
<Constraints> <StreamType>live,recorded,offline</StreamType>
<PublicProfile/>
<Name></Name><NoKeywords/>
<RelativeURLs/>
<NoKeywords/>
</Constraints>
</AvailablePerformers>
</SMLQuery>';
$url='http://affiliate.streamate.com/?????/SMLResult.xml';
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_TIMEOUT,120);
curl_setopt($curl,CURLOPT_HTTPHEADER,array (
'Content-Type: application/xml; charset=utf-8',
));
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $curlData);
$result = curl_exec($curl);
curl_close ($curl);
$xml = simplexml_load_string ($result);
// $json = json_encode($xml);
// $array = json_decode($json,TRUE);
?>
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Website Feed</title>
<description>Website Feed coded manually</description>
<link>yourdomain.com</link>;
<?php
foreach ($xml->AvailablePerformers->Performer as $perf) {
<item>
<title><php? echo ".$perf->attributes()->Name ."?></title>
<description><php? echo " .$perf->Descriptions->About ."?></description>
<link><php? echo "<a href='http://www.example.com /cam/".$perf->attributes()->Name." /?AFNO=X-0-XXXXXX-XXXXXX&UHNSMTY=XXX?></link>
</item>
</channel>
</rss>
?>
As you already have an XML source and want another XML result, maybe you could try XSLT to directly convert it.
http://www.w3schools.com/xsl/
I am trying to generate an RSS feed for a streamate whitelabel site. The network support have provided me with the bare minimum information on how to generate anything.
This is all they have provided to generate info about live performers:
"This query is used to retrieve information about performers.
You will receive the information packaged into an XML document.
Please send your XML request by HTTP POST to:
http://affliate.streamate.com/??????/SMLResult.xml
Be sure to send a “Content-type: text/xml” header as part of the HTTP request. You
may replace streamate.com with a branded domain, if one is available to you, to have
URLs returned with that same branded domain instead of streamate.com"
So, I have managed to find out how to pull live info from their XML feed into a php page, by searching for a snippet of code, but this is not an RSS feed that I can utilise (to feed into social networks, etc).
If anyone can please give me some pointers on how to utilise their XML file into an RSS feed which links to my own whitelabe domain (as they have half instructed above).
Below is the code I have found and used to generate the live info on a php page (I just wish it was an RSS feed).
<?php
$curlData = '<?xml version="1.0" encoding="UTF-8"?>
<SMLQuery>
<Options MaxResults="20"/>
<AvailablePerformers Exact="false" PageNum="1" CountTotalResults="true">
<Include>
<Country/>
<Headline/>
<Descriptions></Descriptions>
<Rating/>
<Age/>
<Gender/>
<Media>biopic</Media>
<FreeChatSort/>
<PerformanceSort/>
</Include>
<Constraints> <StreamType>live,recorded,offline</StreamType>
<PublicProfile/>
<Name></Name><NoKeywords/>
<RelativeURLs/>
<NoKeywords/>
</Constraints>
</AvailablePerformers>
</SMLQuery>';
$url='http://affiliate.streamate.com/????/SMLResult.xml';
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_TIMEOUT,120);
curl_setopt($curl,CURLOPT_HTTPHEADER,array ('Content-Type: application/xml; charset=utf-8',));
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $curlData);
$result = curl_exec($curl);
curl_close ($curl);
$xml = simplexml_load_string ($result);
// $json = json_encode($xml);
// $array = json_decode($json,TRUE);
print_r ($result);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Cam Testing Going On :)</title>
<link rel="stylesheet" type="text/css" href="streamstyle.css" />
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body id="home">
<?php
foreach ($xml->AvailablePerformers->Performer as $perf) {
echo "<br />";
echo "<p>";
echo "<strong>Name: </strong>" .$perf->attributes()->Name ."<br />";
echo "<a href='http://www.mywhitelabeldomain.com/cam/".$perf->attributes()->Name."/?AFNO=X-0-XXXXXX-XXXXXX&UHNSMTY=XXX' target='_blank'><img src='http://mywhitelabeldomain.com".$perf->Media->Pic->Thumb->attributes()->Src."' /></a><br />";
echo "<strong>Age: </strong>" .$perf->attributes()->Age ."<br />";
echo "<strong>About: </strong>" .$perf->attributes()->Headline ."<br />";
echo "<strong>Description: </strong>" .$perf->Descriptions->About ."<br />";
echo "<strong>StreamType: </strong>" .$perf->attributes()->StreamType ."<br />";
echo "<p>";
echo "<br />";
}
?>
</body>
</html>
and here is one of the example snippets that the affiliate network provided, which I can see is part of the above code I found:
XML Request Structure
Example, Real World Generic
<?xml version="1.0" encoding="UTF-8"?>
<SMLQuery>
<Options MaxResults="50" />
<AvailablePerformers QueryId=”MyGenericQuery”>
<Include>
<Descriptions />
<Media>staticbiopic</Media>
</Include>
<Constraints>
<PublicProfile />
<StreamType>live</StreamType>
</Constraints>
</AvailablePerformers>
</SMLQuery>
Thanks for any advice anyone can give me. I really want to learn how to do this.
I am aware that an RSS feed xml file looks like this:
<?xml version="1.0" encoding="utf-8"?> <rss version="2.0"> <channel> <title>Website Feed</title> <description>Website Feed coded manually</description> <link>yourdomain.com</link>; <item> <title>A Special Event</title> <description>A Special Teleconference for our customers about our products</description> <link>yourdomain.com/events.htm</link>; </item> </channel> </rss>
But I am wanting to combine the data from the external xml file (from my first code snippet at the begining of this post) into an rss feed xml file, but retaining the use of my whitelabel url in the links.
UPDATE
Ok, I have tried merging some of the php code into an xml doc using an rss feed code structure, but obviously I am failing as I do not quite understand what I am doing here. I have searched google endlessly on this. Here is my attempt at merging the codes:
<?php
$curlData = '<?xml version="1.0" encoding="UTF-8"?>
<SMLQuery>
<Options MaxResults="20"/>
<AvailablePerformers Exact="false" PageNum="1" CountTotalResults="true">
<Include>
<Country/>
<Headline/>
<Descriptions></Descriptions>
<Rating/>
<Age/>
<Gender/>
<Media>biopic</Media>
<FreeChatSort/>
<PerformanceSort/>
</Include>
<Constraints> <StreamType>live,recorded,offline</StreamType>
<PublicProfile/>
<Name></Name><NoKeywords/>
<RelativeURLs/>
<NoKeywords/>
</Constraints>
</AvailablePerformers>
</SMLQuery>';
$url='http://affiliate.streamate.com/?????/SMLResult.xml';
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_TIMEOUT,120);
curl_setopt($curl,CURLOPT_HTTPHEADER,array (
'Content-Type: application/xml; charset=utf-8',
));
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $curlData);
$result = curl_exec($curl);
curl_close ($curl);
$xml = simplexml_load_string ($result);
// $json = json_encode($xml);
// $array = json_decode($json,TRUE);
print_r ($result);
?>
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Website Feed</title>
<description>Website Feed coded manually</description>
<link>yourdomain.com</link>;
<?php
foreach ($xml->AvailablePerformers->Performer as $perf) {
<item>
<title><php? echo ".$perf->attributes()->Name ."?></title>
<description><php? echo " .$perf->Descriptions->About ."?></description>
<link><php? echo "<a href='http://www.mydomain.com/cam/".$perf->attributes()->Name." /?AFNO=X-0-XXXXXX-XXXXXX&UHNSMTY=XXX?></link>;
</item>
</channel>
</rss>
?>
UPDATE 2
I have removed the print_r() as instructed and saved the following code as a php file, uploaded it, but all I am seeing is a blank white page. I dont know what to change re the header tag so can you explain where the header code should be and what I need to add/change please?
This is the code I now have, saved as a php file (or should it be an xml file? as I want it as an RSS feed, not a php webpage).
<?php
$curlData = '<?xml version="1.0" encoding="UTF-8"?>
<SMLQuery>
<Options MaxResults="20"/>
<AvailablePerformers Exact="false" PageNum="1" CountTotalResults="true">
<Include>
<Country/>
<Headline/>
<Descriptions></Descriptions>
<Rating/>
<Age/>
<Gender/>
<Media>biopic</Media>
<FreeChatSort/>
<PerformanceSort/>
</Include>
<Constraints> <StreamType>live,recorded,offline</StreamType>
<PublicProfile/>
<Name></Name><NoKeywords/>
<RelativeURLs/>
<NoKeywords/>
</Constraints>
</AvailablePerformers>
</SMLQuery>';
$url='http://affiliate.streamate.com/?????/SMLResult.xml';
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_TIMEOUT,120);
curl_setopt($curl,CURLOPT_HTTPHEADER,array (
'Content-Type: application/xml; charset=utf-8',
));
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $curlData);
$result = curl_exec($curl);
curl_close ($curl);
$xml = simplexml_load_string ($result);
// $json = json_encode($xml);
// $array = json_decode($json,TRUE);
?>
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Website Feed</title>
<description>Website Feed coded manually</description>
<link>yourdomain.com</link>;
<?php
foreach ($xml->AvailablePerformers->Performer as $perf) {
<item>
<title><php? echo ".$perf->attributes()->Name ."?></title>
<description><php? echo " .$perf->Descriptions->About ."?></description>
<link><php? echo "<a href='http://www.mydomain.com/cam/".$perf->attributes()->Name." /?AFNO=X-0-XXXXXX-XXXXXX&UHNSMTY=XXX?></link>
</item>
</channel>
</rss>
?>
Just bumping this thread in hope someone can assist? Thanks.
UPDATE
ok I understand that I need to set the header content type. I have searched the web and found this:
<?php
header("Content-type:rss/xml");
?>
Is this correct for an rss feed? Where exactly in the page do I put this?
Also yet in my original code pasted above there is already a bit of code relating to content type stating:
'Content-Type: application/xml; charset=utf-8',
));
All I want is my original code to be an RSS Feed. I can't believe how difficult this is proving to find information on.
You want to turn your example into a usable RSS feed you can plug into your WL and other types of sites. This is very easy with what you had previously. As an example lets pretend you create a PHP page on the example domain below:
hxxp://www.example.com/pull_xml.php
Put inside it this content:
<?php
$curlData = '<?xml version="1.0" encoding="UTF-8"?>
<SMLQuery>
<Options MaxResults="20"/>
<AvailablePerformers Exact="false" PageNum="1" CountTotalResults="true">
<Include>
<Country/>
<Headline/>
<Descriptions></Descriptions>
<Rating/>
<Age/>
<Gender/>
<Media>biopic</Media>
<FreeChatSort/>
<PerformanceSort/>
</Include>
<Constraints> <StreamType>live,recorded,offline</StreamType>
<PublicProfile/>
<Name></Name><NoKeywords/>
<RelativeURLs/>
<NoKeywords/>
</Constraints>
</AvailablePerformers>
</SMLQuery>';
$url='http://affiliate.streamate.com/????/SMLResult.xml';
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_TIMEOUT,120);
curl_setopt($curl,CURLOPT_HTTPHEADER,array ('Content-Type: application/xml; charset=utf-8',));
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $curlData);
$result = curl_exec($curl);
curl_close ($curl);
echo $result;
?>
When you load that page into your browser you will see that it is an XML feed suitable for filling up your WL. To create a specific RSS feed from the data to work with a proprietary format expected by a certain service you will have to update your question with what format the feed should take. You can give an example of a feed you wish to emulate.
Also, you can change all URL's to your WL's URL structure by asking for the stream and substituting streamate.com with your whitelabel's domain.
I have been working with some code for many hours today, wondering if someone could point me in a better direction than I'm going now.
I have PHP code that is fetching an array of data by sending XML via send_request_via_curl($host,$path,$content).
My function:
function send_request_via_curl($host,$path,$content)
{
$posturl = "https://" . $host . $path;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $posturl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded"));
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml;charset=utf-8"));
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
return $response;
}
$headers = array(
"Content-type: text/xml;charset=utf-8",
"Accept: application/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"Content-length: " . strlen($content),
);
$content = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetLocations xmlns="http://tempuri.org/">
<AuthLogin>ClientName</AuthLogin>
<UserName>MyUser</UserName>
<Password>SomePassword</Password>
</GetLocations>
</soap:Body>
</soap:Envelope>';
$response = send_request_via_curl($host,$path,$content);
EDIT:
I'm getting closer, I implemented Baba's code and now getting a different error:
Warning: Unknown: Node no longer exists in....
I have the same code from above, with this now processing the response:
if ($response)
{
$xml = new SimpleXMLElement($response);
$xml->registerXPathNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
$path = $xml->xpath("//soap:Body");
$path = $path[0] ;
foreach($path->GetLocationsResponse->GetLocationsResult->SearchLocations->children() as $table)
{
echo $table->Table->LocationName . "<br>";
}
Here's the true XML returned - I noticed Firebug made all the XML lowercase, whereas the source code has capitals mixed in which I think might matter.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetLocationsResponse xmlns="http://tempuri.org/">
<GetLocationsResult>
<SearchLocations>
<Table>
<LocationName>
</Table>
<Table>
<LocationId>103501</LocationId>
<LocationName>Albuquerque, New Mexico, USA</LocationName>
</Table>
<Table>
<LocationId>101600</LocationId>
<LocationName>Atlanta, Georgia, USA</LocationName>
</Table>
</SearchLocations>
</GetLocationsResponse>
</GetLocationsResult>
</soap:Body>
</soap:Envelope>
THANKS!!!
The response you got is not HTML but XML but it looks like Your XML is wrong there is an invalid tag or you must have made mistake ... see
<LocationName>Hawaii</Location>
^--- it should be LocationName
It should be like this
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getlocationsresponse xmlns="http://tempuri.org">
<getlocationsresult>
<SearchLocations>
<Table>
<LocationID>10322</LocationID>
<LocationName>Hawaii</LocationName>
</Table>
</SearchLocations>
</getlocationsresult>
</getlocationsresponse>
</soap:Body>
</soap:Envelope>
Read This XML
$xml = new SimpleXMLElement($data);
$xml->registerXPathNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
$path = $xml->xpath("//soap:Body");
$path = $path[0] ;
foreach($path->getlocationsresponse->getlocationsresult->SearchLocations->children() as $table)
{
echo $table->LocationName . "<br>";
}
Output
Hawaii
------ Edit --------
Your new XML is wrong again .. this is what it should look like http://codepad.org/JgJfqnrA
Baba is correct, the built in functions for parsing XML are the best way to do this but you could also use regex if the XML is really sent back with mismatching tags.
function regex_all( $capture, $haystack, $return=1 ) {
preg_match_all( "#$capture#", $haystack, $match );
return $match[ $return ];
}
foreach( regex_all('<LocationName>(.*?)<\/', $data) as $locationName ) {
echo "$locationName<br>";
}
This would not be the preferred method because the regex isn't as reliable.
What I am trying to get currently is just the attribute of gd:email that is the "address=" only nothing else as of the moment. Which I can get to the xml portion, heck I can even get any given think per say as long as its within tags like but to get the attribute of any given one like in my case.. I am completely confused on. I used to know how to do it but its been so long since I did anything that wasn't simple for XML useage. so I done messed my own self up..
<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gContact='http://schemas.google.com/contact/2008' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:gd='http://schemas.google.com/g/2005'>
<id>xxxxxxxxxxxxxx#gmail.com</id>
<updated>2011-06-30T00:07:48.706Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/contact/2008#contact'/>
<title type='text'>Taco Bells's Contacts</title>
<link rel='alternate' type='text/html' href='http://www.google.com/'/>
<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/full'/>
<link rel='http://schemas.google.com/g/2005#post' type='application/atom+xml' href='http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/full'/>
<link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/full/batch'/>
<link rel='self' type='application/atom+xml' href='http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/full?max-results=5'/>
<link rel='next' type='application/atom+xml' href='http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/full?start-index=6&max-results=5'/>
<author>
<name>Taco Bell</name>
<email>xxxxxxxxxxxxxx#gmail.com</email>
</author>
<generator version='1.0' uri='http://www.google.com/mate/feeds'>Contacts</generator>
<openSearch:totalResults>90</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>5</openSearch:itemsPerPage>
<entry>
<id>http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/base/0</id>
<updated>2010-01-27T00:11:57.430Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/contact/2008#contact'/>
<title type='text'>Taco B</title>
<link rel='http://schemas.google.com/contacts/2008/rel#edit-photo' type='image/*' href='http://www.google.com/mate/feeds/photos/media/xxxxxxxxxxxxxx%40gmail.com/0/8_XL_JoAPon1k7SNixI2iA'/>
<link rel='http://schemas.google.com/contacts/2008/rel#photo' type='image/*' href='http://www.google.com/mate/feeds/photos/media/xxxxxxxxxxxxxx%40gmail.com/0'/>
<link rel='self' type='application/atom+xml' href='http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/full/0'/>
<link rel='edit' type='application/atom+xml' href='http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/full/0/1264551117430000'/>
<gd:email rel='http://schemas.google.com/g/2005#other' address='xxxxxxxxxxxxxx#gmail.com' primary='true'/>
</entry>
<entry>
<id>http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/base/1</id>
<updated>2007-08-01T18:02:04.410Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/contact/2008#contact'/>
<title type='text'></title>
<link rel='http://schemas.google.com/contacts/2008/rel#edit-photo' type='image/*' href='http://www.google.com/mate/feeds/photos/media/xxxxxxxxxxxxxx%40gmail.com/1/1B2M2Y8AsgTpgAmY7PhCfg'/>
<link rel='self' type='application/atom+xml' href='http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/full/1'/>
<link rel='edit' type='application/atom+xml' href='http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/full/1/1185991324410001'/>
<gd:email rel='http://schemas.google.com/g/2005#other' address='xxxxxxxxxxxxxx#sbcglobal.net' primary='true'/>
</entry>
<entry>
<id>http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/base/2</id>
<updated>2010-01-27T00:11:57.430Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/contact/2008#contact'/>
<title type='text'>Steve Sattler</title>
<link rel='http://schemas.google.com/contacts/2008/rel#edit-photo' type='image/*' href='http://www.google.com/mate/feeds/photos/media/xxxxxxxxxxxxxx%40gmail.com/2/1B2M2Y8AsgTpgAmY7PhCfg'/>
<link rel='self' type='application/atom+xml' href='http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/full/2'/>
<link rel='edit' type='application/atom+xml' href='http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/full/2/1264551117430000'/>
<gd:email rel='http://schemas.google.com/g/2005#other' address='xxxxxxxxxxxxxx#yahoo.com' primary='true'/>
</entry>
<entry>
<id>http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/base/3</id>
<updated>2010-01-27T00:11:57.430Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/contact/2008#contact'/>
<title type='text'>Michael Montana</title>
<link rel='http://schemas.google.com/contacts/2008/rel#edit-photo' type='image/*' href='http://www.google.com/mate/feeds/photos/media/xxxxxxxxxxxxxx%40gmail.com/3/1B2M2Y8AsgTpgAmY7PhCfg'/>
<link rel='self' type='application/atom+xml' href='http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/full/3'/>
<link rel='edit' type='application/atom+xml' href='http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/full/3/1264551117430000'/>
<gd:email rel='http://schemas.google.com/g/2005#other' address='xxxxxxxxxxxxxx#comcast.net' primary='true'/>
</entry>
<entry>
<id>http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/base/4</id>
<updated>2007-08-01T18:02:04.410Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/contact/2008#contact'/>
<title type='text'></title>
<link rel='http://schemas.google.com/contacts/2008/rel#edit-photo' type='image/*' href='http://www.google.com/mate/feeds/photos/media/xxxxxxxxxxxxxx%40gmail.com/4/1B2M2Y8AsgTpgAmY7PhCfg'/>
<link rel='self' type='application/atom+xml' href='http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/full/4'/>
<link rel='edit' type='application/atom+xml' href='http://www.google.com/mate/feeds/contacts/xxxxxxxxxxxxxx%40gmail.com/full/4/1185991324410001'/>
<gd:email rel='http://schemas.google.com/g/2005#other' address='xxxxxxxxxxxxxx#courant.com' primary='true'/>
</entry>
</feed>
with code that looks like (this is the whole script (currently))
$user = "xxxxxxxxxxxxxxxxxxx#gmail.com";
$password = "xxxxxxxxxxxx";
// ref: http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html
// step 1: login
$login_url = "https://www.google.com/accounts/ClientLogin";
$fields = array(
'Email' => $user,
'Passwd' => $password,
'service' => 'cp', // <== contact list service code
'source' => 'test-google-contact-grabber',
'accountType' => 'GOOGLE',
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,$login_url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS,$fields);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
$returns = array();
foreach (explode("\n",$result) as $line)
{
$line = trim($line);
if (!$line) continue;
list($k,$v) = explode("=",$line,2);
$returns[$k] = $v;
}
curl_close($curl);
// step 2: grab the contact list
$feed_url = "http://www.google.com/m8/feeds/contacts/$user/full?&max-results=5";
$header = array(
'Authorization: GoogleLogin auth=' . $returns['Auth'],
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $feed_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
$doc = new DOMDocument();
$doc->load($result);
$arrFeeds = array();
foreach ($doc->getElementsByTagName('entry') as $node) {
$monkey = $node->getAttribute('{gd:email}');
$itemRSS = array($monkey->nodeValue);
array_push($arrFeeds, $itemRSS);
}
array_unique($arrFeeds);
Have a look at DOMDocument and DOMXPath. In order to get nodes that are part of a particular namespace, like the email node which is part of the gd namespace, you need to register the namespace with the DOMXPath object using DOMXPath::registerNamespace(). The namespace URI can usually be found at the top of the XML document.
Example:
$doc = new DOMDocument;
$doc->recover = true;
$doc->loadXML($result);
$xpath = new DOMXPath($doc);
$xpath->registerNamespace('gd', 'http://schemas.google.com/g/2005');
$emails = $xpath->query('//gd:email');
foreach ( $emails as $email )
{
echo $email->getAttribute('address');
// To get the title.
// This could also be done using XPath.
// You can also use ->nodeValue instead of ->textContent.
echo $email->parentNode->getElementsByTagName('title')->item(0)->textContent;
}
In the example above, $result is the result of $result = curl_exec($ch);.
$url = 'https://www.google.com/m8/feeds/contacts//full?max-results='.$max_results.'&oauth_token='.$accesstoken.'&alt=json&updated-min=2007-03-16T00:00:00';
function curl_file_get_contents($url)
{
$curl = curl_init();
$userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
//The URL to fetch. This can also be set when initializing a session with curl_init().
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_HTTPHEADER,array('GData-Version: 2.0'));
curl_setopt($curl,CURLOPT_RETURNTRANSFER,TRUE); //TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,5); //The number of seconds to wait while trying to connect.
curl_setopt($curl,CURLOPT_HTTPGET,true);
curl_setopt($curl, CURLOPT_USERAGENT, $userAgent); //The contents of the "User-Agent: " header to be used in a HTTP request.
//curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); //To follow any "Location: " header that the server sends as part of the HTTP header.
//curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE); //To automatically set the Referer: field in requests where it follows a Location: redirect.
curl_setopt($curl, CURLOPT_TIMEOUT, 10); //The maximum number of seconds to allow cURL functions to execute.
//curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); //To stop cURL from verifying the peer's certificate.
$contents = curl_exec($curl);
curl_close($curl);
return $contents;
}