I am using CURL to retrieve the results from a page and on that page is 2 hidden form fields. What I need to do is get the value of the hidden form fields. So basically what I need is some preg_match code to get the value from the following fields:
There are much better ways to accomplish the task like the others have said. But here’s the regular expression to use: (tell me if it doesn’t work, I might have messed up on the quotes)
// Assuming $html_code is the HTML of the entire page
$cvref = preg_replace('/^.*name\\="cvref"\\s+value\\="(.+)"\\>.*$/', '$1', $html_code);
$filekey = preg_replace('/^.*name\\="filekey"\\s+value\\="(.+)"\\>.*$/', '$1', $html_code);
Okay I see. I tried your suggestion, but im getting the following error when trying to load the values of $page_result_1:
Warning: DOMDocument::loadHTML() [function.DOMDocument-loadHTML]: htmlParseEntityRef: no name in Entity, line: 522 in /home/myuser/public_html/mydomain.com/public/users/register-cv-library.php on line 104
I’m going to play the little devil (or evil leprechaun) on your opposite shoulder to Anthony.
Sound advice, but I might go so far as to say that Zaggs is not trying to parse a structured document; in the sense that one might need a tool to provide a programmatic interface to a whole document. Consider the following, almost identical but different in a slight yet meaningful way, snippet based on the Zaggs’ HTML snippet.
Normally, I would too be offering a DOM—(or other more suitable tool)—based answer but the bandwagon is getting tired and old. Those bright young whipper-snappers who, frequenting the places where such topics are raised, so confidently bemoan the practicality of regexes within 50 paces of the acronym HTML are readily becoming quite wearisome.
P.S. If Zaggs likes the look of using the DOM extension to get at his required values, I’ll be happy to sidle up to Anthony to help arrive at a nice solution.
I’m using CURL() like this and it’s returning a string:
$curl_handle = curl_init();
// Set the URL to be processed
curl_setopt($curl_handle, CURLOPT_URL, "http://www.post-url.com/register.php");
// Assign the data to be sent
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $data);
// Return details
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
// Set result var
$page_1_result = curl_exec($curl_handle);