Hi all.

I have a dynamically generated HTML page using PHP. I create my PHP variables and then have them in line with my HTML like so:

<tr>
            <td align="right">Restaurant Subtotal</td>
            <td align="right"><strong><? $subTotal = getSubTotal(); echo money($subTotal);?></strong></td>
          </tr>

I have a need to send the generated HTML to a Web Service API and want to know if there is an easy way to do it. The API only requires the HTML. IT cannot have any embedded PHP of course.

the output contains no php, only the generated html
how does the external api get its data

the output contains no php, only the generated html
how does the external api get its data

I'm sorry for being unclear.
I have to send the API a string of whatever the PHP code generates. It would be easy if all the PHP was separate but it is inline with the HTML. This of course would need to be done before it leaves the server. I'm trying to avoid the whole PHP embedded HEREDOC thing.

something in the user string in the remote api is always enough to uniquely identify the remote api, remote address remote_host http_user_agent etc ( http://php.net/manual/en/reserved.variables.server.php ) , available to php when the file containing the data is requested perhaps an intelligently written version of this example

<?php if $_server['something_testable']='value confirming remote api'; { $subTotal = getSubTotal(); echo money($subTotal);
// repeated ad-nauseum to give all machine readable data fields
exit; } ?>
regular html & generated info for human readable data fields
</body></html>

yes, need more info:
just a thought. you can have code call your dynamic generated page read its contents and then send that to the api. again I don't know what your full issue is.

$to_send = file_get_contents('dynamic.html');
// then use curl to call the api
$URL = 'the_url_for_api';
$ch = curl_init(); // initialize the cURL session
curl_setopt($ch, CURLOPT_URL, $URL);  // tell it which URL to go to (minus the parameters)
// you may not want to 'POST', curl has other options, look them up.
curl_setopt($ch, CURLOPT_POST, 1);  // tell it that you want to send an HTTP POST response
curl_setopt($ch, CURLOPT_POSTFIELDS, $to_send); // pass it the parameters
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ret_value = curl_exec ($ch); // do it
curl_close ($ch); // close the session   
if ($ret_value != '') {		
        // $ret_value should hold the data returned from the api
        // (I used this for a form post, not an api call, so you may have to change the way you use curl to call the api.
	$html = $ret_value;
        echo "$html";
}
// all just a thought on how to handle your brief description of an api post.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.