/    Sign up×
Community /Pin to ProfileBookmark

Data Fetching Help!

I have an xml file.and i need fetch the data using php

[CODE]<?xml version=”1.0″ encoding=”UTF-8″ ?>
<ALEXA VER=”0.9″ URL=”way2sms.com/” HOME=”0″ AID=”=”>
<RLS PREFIX=”http://” more=”203″>
<RL HREF=”www.indyarocks.com/” TITLE=”Indyarocks – Bringing India Together” />
<RL HREF=”www.atrochatro.com/” TITLE=”AtroChatro.com” />
<RL HREF=”www.f9games.com/” TITLE=”F9games – India’s Largest Games Portal” />
<RL HREF=”www.ibibo.com/” TITLE=”ibibo – create blogs, share opinions, questions & answers, sea” />
<RL HREF=”www.bigadda.com/” TITLE=”BigAdda” />
<RL HREF=”www.youmint.com/” TITLE=”YouMint: Free sms to India, send free sms, get paid to invite friends and receiv” />
<RL HREF=”www.bharatmatrimony.com/” TITLE=”BharatMatrimony.com” />
<RL HREF=”www.indiaresults.com/” TITLE=”India Results” />
<RL HREF=”tollywoodvideos.in/” TITLE=”TOLLYWOOD VIDEOS” />
<RL HREF=”www.shine.com/” TITLE=”Seeking Harmony in Neighborhoods Everyday (SHiNE)” />
</RLS>
<SD TITLE=”A” FLAGS=”DMOZ”>
<TITLE TEXT=”Way2SMS” />
<ADDR STREET=”No:89, Road No:9,” CITY=”Hyderabad, AP 500038″ STATE=”” ZIP=”” COUNTRY=”india” />
<PHONE NUMBER=”914023546453″ />
<OWNER NAME=”Way2sms.com” />
<EMAIL ADDR=”[email protected]” />
<LINKSIN NUM=”61″ />
<SPEED TEXT=”7453″ PCT=”7″ />
<POPULARITY URL=”way2sms.com/” TEXT=”1457″ />
<RANK DELTA=”-486″ />
<CHILD SRATING=”0″ />
<REACH RANK=”1699″ />
</SD>
</ALEXA>[/CODE]

and now i want fetch the data from this file.i need to fetch the values such as PHONE NUMBER,OWNER NAME,EMAIL ADDR….seperately and store them in the database could any help me with some php code for fetching the data

Thanks for all your support.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@zahidrafMar 02.2009 — try to parse example and get data and save it into your .......db

Here is a detail artilce on it .


http://www.codehelp.co.uk/php/xmlparse1.php

Technology News
Copy linkTweet thisAlerts:
@sweetdragonsauthorMar 02.2009 — Thank for your help! But didn't get the correct code so could u give me the exact code for my above example ...plz
Copy linkTweet thisAlerts:
@zahidrafMar 02.2009 — I will see if i can ge time to make it one or post in someo ther forum may be you can get some help .

Thanks
Copy linkTweet thisAlerts:
@john_de116Mar 02.2009 — Hi use this code. Call this function xml2array. $url is your filename. It will give the result.

//xml2array($url, $get_attributes = 1, $priority = 'tag')

<?php

function xml2array($url, $get_attributes = 1, $priority = 'tag')

{

$contents = "";

if (!function_exists('xml_parser_create'))

{

return array ();

}

$parser = xml_parser_create('');

if (!($fp = @ fopen($url, 'rb')))

{

return array ();

}

while (!feof($fp))

{

$contents .= fread($fp, 8192);

}

fclose($fp);

xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");

xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);

xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);

xml_parse_into_struct($parser, trim($contents), $xml_values);

xml_parser_free($parser);

if (!$xml_values)

return; //Hmm...

$xml_array = array ();

$parents = array ();

$opened_tags = array ();

$arr = array ();

$current = & $xml_array;

$repeated_tag_index = array ();

foreach ($xml_values as $data)

{

unset ($attributes, $value);

extract($data);

$result = array ();

$attributes_data = array ();

if (isset ($value))

{

if ($priority == 'tag')

$result = $value;

else

$result['value'] = $value;

}

if (isset ($attributes) and $get_attributes)

{

foreach ($attributes as $attr => $val)

{

if ($priority == 'tag')

$attributes_data[$attr] = $val;

else

$result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'

}

}

if ($type == "open")

{

$parent[$level -1] = & $current;

if (!is_array($current) or (!in_array($tag, array_keys($current))))

{

$current[$tag] = $result;

if ($attributes_data)

$current[$tag . '_attr'] = $attributes_data;

$repeated_tag_index[$tag . '_
' . $level] = 1;

$current = & $current[$tag];

}

else

{

if (isset ($current[$tag][0]))

{

$current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;

$repeated_tag_index[$tag . '_
' . $level]++;

}

else

{

$current[$tag] = array (

$current[$tag],

$result

);

$repeated_tag_index[$tag . '_' . $level] = 2;

if (isset ($current[$tag . '_
attr']))

{

$current[$tag]['0_attr'] = $current[$tag . '_attr'];

unset ($current[$tag . '_
attr']);

}

}

$last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;

$current = & $current[$tag][$last_item_index];

}

}

elseif ($type == "complete")

{

if (!isset ($current[$tag]))

{

$current[$tag] = $result;

$repeated_tag_index[$tag . '_
' . $level] = 1;

if ($priority == 'tag' and $attributes_data)

$current[$tag . '_attr'] = $attributes_data;

}

else

{

if (isset ($current[$tag][0]) and is_array($current[$tag]))

{

$current[$tag][$repeated_tag_index[$tag . '_
' . $level]] = $result;

if ($priority == 'tag' and $get_attributes and $attributes_data)

{

$current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;

}

$repeated_tag_index[$tag . '_' . $level]++;

}

else

{

$current[$tag] = array (

$current[$tag],

$result

);

$repeated_tag_index[$tag . '_
' . $level] = 1;

if ($priority == 'tag' and $get_attributes)

{

if (isset ($current[$tag . '_attr']))

{

$current[$tag]['0_attr'] = $current[$tag . '_
attr'];

unset ($current[$tag . '_attr']);

}

if ($attributes_data)

{

$current[$tag][$repeated_tag_index[$tag . '_
' . $level] . '_attr'] = $attributes_data;

}

}

$repeated_tag_index[$tag . '_
' . $level]++; //0 and 1 index is already taken

}

}

}

elseif ($type == 'close')

{

$current = & $parent[$level -1];

}

}

return ($xml_array);

}

?>
×

Success!

Help @sweetdragons spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...