473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Need help PHP - XML

Hello,
I hope some one can help me with this.
I need to output xml data from a remote server into a pulldown menu.

This is what i already done.

<?

$url = "https://secure.virtuelekassa.nl/api/xml/ideal.asp";

$page = "/ideal.asp";



$request_xml = "<?xml version=\"1.0\" ?>\n";

$request_xml .= "<request>\n";

$request_xml .= "<test>true</test>\n";

$request_xml .= "<type>banklist</type>\n";

$request_xml .= "</request>\n";



$post_string = $request_xml;



$header = "POST ".$url." HTTP/1.0 \r\n";

$header .= "MIME-Version: 1.0 \r\n";

$header .= "Content-type: application/PTI26 \r\n";

$header .= "Content-length: ".strlen($post_string)." \r\n";

$header .= "Content-transfer-encoding: text \r\n";

$header .= "Request-number: 1 \r\n";

$header .= "Document-type: Request \r\n";

$header .= "Interface-Version: Test 1.4 \r\n";

$header .= "Connection: close \r\n\r\n";

$header .= $post_string;



$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_TIMEOUT, 4);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);


$data = curl_exec($ch);

if (curl_errno($ch)) {

print curl_error($ch);

} else {

// just for testing
print ("$data");


curl_close($ch);

}

?>

When i run the file i get this.

<?xml version="1.0" encoding="UTF-8"?>
<response>
<type>banklist</type>
<bank>
<bankid>0031</bankid>
<bankname>ABN Amro</bankname>
</bank>
<bank>
<bankid>0081</bankid>
<bankname>Fortis</bankname>
</bank>
<bank>
<bankid>0721</bankid>
<bankname>Postbank</bankname>
</bank>
<bank>
<bankid>0021</bankid>
<bankname>Rabobank</bankname>
</bank>
<bank>
<bankid>0751</bankid>
<bankname>SNS Bank</bankname>
</bank>
</response>


This works fine, but how can i put this $data into a pulldown menu.?
Please if you can help me with a working sample you make me real happy.
Thank you

Hans
Jan 11 '08 #1
2 1444
pedalpete
110 100+
Hey Hank,

I do something very similar with an xml file and php.

I use preg_match_all and preg_match loops.

Not sure if you are making the xml locally or if it comes from the remote server,
to get the xml, i use this, but the content is already in xml on the remote server
I use this to get my xml page
Expand|Select|Wrap|Line Numbers
  1. // Get the xml page
  2. $url = "address where xml is located";
  3. $data = implode("", file($url));
  4.  
but once you have the xml in a variable (as above) you can use the below
I think you would want something like this

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. echo "<select name=\"banks\">";
  4. // Get each bank
  5.  preg_match_all ("/<bank>([^`]*?)<\/bank>/", $data, $matches);
  6.  
  7. // then go through each to get the bank details from the xml
  8.  
  9. foreach ($matches[0] as $match) {
  10.  
  11. // get bankid
  12. preg_match ("/<bankid>([^`]*?)<\/bankid>/", $match, $temp);
  13.     $bankid = $temp['1'];
  14.  
  15. // get bankname
  16. preg_match ("/<bankname>([^`]*?)<\/bankname>/", $match, $temp);
  17.     $bankname = $temp['1'];
  18.  
  19.     echo "<option value=\"$bankid\">$bankname</option";
  20. }
  21.  
Jan 12 '08 #2
Thank you for repllying,
this is what i was looking for, it works great!
The xml file is recived from a remote server.
Gr. Hans
Jan 12 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sofia | last post by:
My name is Sofia and I have for many years been running a personals site, together with my partner, on a non-profit basis. The site is currently not running due to us emigrating, but during its...
6
by: Robert Maas, see http://tinyurl.com/uh3t | last post by:
System login message says PHP is available, so I tried this: http://www.rawbw.com/~rem/HelloPlus/h.php It doesn't work at all. Browser just shows the source. What am I doing wrong?
0
by: Gregory Nans | last post by:
hello, i need some help to 'tree-ify' a string... for example i have strings such as : s = """A(here 's , B(A ) silly test) C(to show D(what kind) of stuff i need))""" and i need to...
7
by: Mike Kamermans | last post by:
I hope someone can help me, because what I'm going through at the moment trying to edit XML documents is enough to make me want to never edit XML again. I'm looking for an XML editor that has a...
8
by: JustSomeGuy | last post by:
I need to write an new class derived from the list class. This class stores data in the list to the disk if an object that is added to the list is over 1K in size. What methods of the std stl...
3
by: Bob.Henkel | last post by:
I write this to tell you why we won't use postgresql even though we wish we could at a large company. Don't get me wrong I love postgresql in many ways and for many reasons , but fact is fact. If...
2
by: Michael R. Pierotti | last post by:
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$") Dim m As Match = reg.Match(txtIPAddress.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show("You need to enter a...
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.