Re: convert hidden form to get url
| From: | Matt M. | Date: | Mon, 20 Dec 2004 19:12:51 +0000 |
| Subject: | Re: convert hidden form to get url | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-204750@lists.php.net to get a copy of this message | ||
> Sorry for not been clear. The snippet of html is code I am getting
> dynamically using curl from another website. I want to then convert that
> html code into a url like
>
> http://www.somewebsite.co.uk/Availability?NUM_OF_ADTS=1&CABIN=E&B1_DAY=27.
you need something to parse the html, I found this:
http://php-html.sourceforge.net/
and here is a quick script to try:
include ("htmlparser.inc");
$htmlText = '<form
action="http://www.somewebsite.co.uk/Availability.cgi"
method="POST"
name="flightsForm" id="flightsForm">
<input type="hidden" name="NUM_OF_ADTS" value="1"/>
<input type="hidden" name="CABIN" value="E"/>
<input type="hidden" name="B1_DAY" value="27"/>
</form>';
$parser = new HtmlParser ($htmlText);
while ($parser->parse()) {
// Data you can use here:
//
// $parser->iNodeType
// $parser->iNodeName
// $parser->iNodeValue
// $parser->iNodeAttributes
if ($parser->iNodeType == NODE_TYPE_ELEMENT) {
$tmp = $parser->iNodeAttributes;
if($parser->iNodeName == 'form') {
$url = $tmp['action'];
} elseif($parser->iNodeName == 'input') {
$qs[$tmp['name']] = $tmp['value'];
}
}
}
$tmp = array();
foreach($qs as $key => $value) {
print "$key => $value <br />";
$tmp[] = $key.'='.urlencode($value);
}
$url .= '?'.implode('&',$tmp);
print 'url='.$url;