0
<?xml version="1.0" encoding="UTF-8"?>
<ALEXA VER="0.9" URL="infosys.com/" HOME="0" AID="=">

   <RLS PREFIX="http://" more="62">
   <RL HREF="wipro.com/" TITLE="Wipro Corporation"/>
   <RL HREF="tcs.com/" TITLE="Tata Consultancy Services"/>
   <RL HREF="satyam.com/" TITLE="Satyam Computer Services Ltd"/>
   <RL HREF="ibm.com/" TITLE="IBM Corporation"/>
   <RL HREF="rediff.com/" TITLE="Rediff.com India Ltd."/>
   <RL HREF="moneycontrol.com/" TITLE="MoneyControl.com"/>
   <RL HREF="in.com/" TITLE="IN.com"/>
   <RL HREF="google.co.in/" TITLE="Google India"/>
   <RL HREF="www.stiknowledge.com/" TITLE="Business Process Outsourcing | Help Desk    Outsourcing And Certification"/>
   <RL HREF="www.sourcinginterests.org/" TITLE="Sourcing Interests Group"/>
   <RL HREF="www.dice.com/" TITLE="www.dice.com/"/>
   </RLS>
   <SD TITLE="A" FLAGS="DMOZ" HOST="infosys.com">
   <TITLE TEXT="Infosys"/>
   <ADDR STREET=" 44, Electronics City,  Hosur Road" CITY=" Bangalore,  KARNATAKA  560 100" STATE="" ZIP="" COUNTRY=" India" />
   <CREATED DATE="17-Jul-1992" DAY="17" MONTH="07" YEAR="1992"/>
   <PHONE NUMBER="91 80 852 0261"/>
   <OWNER NAME="Infosys Technologies Limited"/>
   <EMAIL ADDR="[email protected]"/>
   <LANG LEX="en" CODE="us-ascii"/>
   <LINKSIN NUM="2858"/>
  <SPEED TEXT="1308" PCT="55"/>
  <REVIEWS AVG="5.0" NUM="1"/>
  <CHILD SRATING="0"/>
   </SD>

   <KEYWORDS>
   <KEYWORD VAL="Karnataka"/>
   <KEYWORD VAL="Bangalore"/>
   </KEYWORDS><DMOZ>
   <SITE BASE="infosys.com/" TITLE="Infosys" DESC="Infosys (NASDAQ:INFY) defines, designs and delivers IT enabled business solutions. These provide you with strategic differentiation and operational superiority, thereby increasing your competitiveness. Each solution is delivered with the industry-benchmark Infosys Predictability that gives you peace of mind.">
   <CATS>
   <CAT ID="Top/Computers/Software/Consultants" TITLE="Software/Consultants" CID="379688"/>
  <CAT ID="Top/Regional/Asia/India/Karnataka/Localities/Bangalore/Business_and_Economy/Computers_and_Internet/Software" TITLE="Computers and Internet/Software" CID="497626"/>
  </CATS>
  </SITE>
  </DMOZ>
  <SD>
  <POPULARITY URL="infosys.com/" TEXT="15422"/>
  <REACH RANK="17335"/>
  <RANK DELTA="+1"/>
   </SD>
   </ALEXA>

i have used $xml= new SimpleXMLElement('xml data here') then used $x=$xml->xpath('/ALEXA); i am getting how to access LINKSIN NUM and REACH RANK here. if i send the $x in foreach like foreach($x as $y){ $y->LINKSIN NUM; } it will throw the error since there is a gap between LINKSIn and NUM

2

2 Answers 2

3

This should work:

$xml = simplexml_load_string($dataHere);
$rank = (int)$xml->SD->REACH['RANK'];

Documentation: https://www.php.net/simplexml_load_string

If you have an URL for the xml:

$xml = simplexml_load_file($URL_to_file);
Sign up to request clarification or add additional context in comments.

3 Comments

$rank = (int)$xml->SD->REACH['rank'];
$rank = (int)$xml->SD->REACH['RANK'];. Case matters.
$rank = (int)$xml->SD->REACH['RANK']; is not working, when i run the file, the rank cominga s zero.
1

Try this:

$xml = simplexml_load_string($xml);
$links = $xml->xpath('//SD/LINKSIN');
$reach = $xml->xpath('//SD/REACH');

$num  = (int)$links[0]['NUM'];
$rank = (int)$reach[0]['RANK'];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.