Forms with php/curl

software development



I’ve spent the last 48 hours initiating myself with php/curl after discovering that the fopen() function was not allowed on DH shared servers.

My need is quite simple and I think I managed the hardest part. But stupidly, I’m blocked with something that is probably dead simple and maybe someone here can help.

A web site authorized me tu use their API and search their image database from my own web site. They only have a 1 page documentation showing a URL request lookalike and a description of the XML elements received when the request is successful.

I’m at the point where I managed to create a php file which fetch an example request (always the same) and parse it in a straight and simple table with SimpleXML.

You can check it here:

The code of my script is the following:


<?php function My_simplexml_load_file($URL) { $ch = curl_init($URL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); $xml = simplexml_load_string(curl_exec($ch)); curl_close($ch); return $xml; } $xml = My_simplexml_load_file(''); if (empty($xml)) { print "Sorry , I could not find images matching your query.
Verify or modify your keywords."; } else { print "

$xml->totalResults search results for your query
$xml->partialResults are shown on this page

"; foreach ($xml->items->item as $item){ print " "; } print "
Dreamstime Image N° imageURL\" alt=\"Image labeled $item->title on Dreamstime\" target=\"_blank\">$item->imageID Label: $item->title Purchased $item->downloads times imageURL\" alt=\"Image labeled $item->title on Dreamstime\" target=\"_blank\">mediumThumb\" title =\"Image labeled $item->title on Dreamstime\">
"; } ?>


So my problem with all that is to understand the logic of the form I want to create and how I pass the “post” values to this fetchparser script I did (and how i should modify it).

1- Do I have to crate a stand alone php which will contain only the code?
2- Do I have to set instead of the website?

That is how I understand the concept but if I’m right, I don’t know, and I can’t find how to transfer the content of the text field (containing the keywords) into the $url I used to fetxh the xml page with php/curl.

I hope my post was not as confused as I am.

Thanks in advance