dminder Posted April 9, 2010 Share Posted April 9, 2010 I am setting up a special page to do address verification from the USPS. I found some code that I am testing to see if it works and be able to modify it to my purposes. HOWEVER, the code I have is not working and continually gives me the error: Parse error: syntax error, unexpected $end in /home/shoret6/public_html/USPS/usps_address_verify.php on line 47Here is the code: <?php function validateAddress() { $xmlstr = <<<XML <AddressValidateRequest USERID="XXXXXXX"> <Address ID="0"> <Address1></Address1> <Address2></Address2> <City></City> <State></State> <Zip5></Zip5> <Zip4></Zip4> </Address> </AddressValidateRequest> XML; $xml = new SimpleXMLElement($xmlstr); $h = new http(); // Populate Address $xml->Address->Address2 = '1600 Pennsylvania Ave NW'; $xml->Address->Address1 = ''; $xml->Address->City = 'Washington'; $xml->Address->State = 'DC'; $xml->Address->Zip5 = '20500'; // Prepare for XML call $h->xmlrequest = $xml->asXML(); $output = str_replace(array("\n",'<?xml version="1.0"?>',"\t",),array('','',''), $xml->asXML()); $url = 'http://TESTING.ShippingAPIs.com/ShippingAPItest.dll?API=Verify&XML='.urlencode($output); // Submit data and get results $h->fetch($url,0,'','','','GET'); print_r($h->body); die(); // Put results into XML object $xml = new SimpleXMLElement($h->body); return $xml; } $xmlverify = validateAddress(); print_r($xmlverify); ?> I think that it has to do with the $output line having a ?> in even when I remove that line, I still get the error. Thank you in advance!!D Link to comment Share on other sites More sharing options...
jeffman Posted April 9, 2010 Share Posted April 9, 2010 For some stupid reason, the terminator of a heredoc must be absolutely at the left margin. No whitespace allowed. I'm referring to this line: XML; I can't be certain, but I suspect that is the issue. Unexpected end errors usually are caused by something much higher up in the document, like a missing brace or other structure terminator. Link to comment Share on other sites More sharing options...
ShadowMage Posted April 9, 2010 Share Posted April 9, 2010 I think there might be a problem with this line:print_r($h->body); die();It may not be producing the error but it is definitely going to produce unexpected results. It will always kill the script before it finishes. Link to comment Share on other sites More sharing options...
jeffman Posted April 9, 2010 Share Posted April 9, 2010 @jklothI assumed that was a debugging line. Don't think it would throw an error. OTOH, is $h->body really a PHP array? Link to comment Share on other sites More sharing options...
ShadowMage Posted April 9, 2010 Share Posted April 9, 2010 I assumed that was a debugging line.Ah. Could be... Link to comment Share on other sites More sharing options...
dminder Posted April 9, 2010 Author Share Posted April 9, 2010 I changed it to this: function validateAddress() { $xmlstr = <<<XML <AddressValidateRequest USERID="XXXXXXX"> <Address ID="0"> <Address1></Address1> <Address2></Address2> <City></City> <State></State> <Zip5></Zip5> <Zip4></Zip4> </Address> </AddressValidateRequest>XML; and not i am getting: Fatal error: Class 'http' not found in x.php on line 18Ahh the joys of programming!! Link to comment Share on other sites More sharing options...
jeffman Posted April 9, 2010 Share Posted April 9, 2010 It doesn't like this line: $h = new http(); Do you have a class constructor called http() ? Do you need to include a file to access it? Were you thinking of some other built-in object support? There is an HttpRequest object in PHP 5 and newer. It doesn't have a fetch method, however. Link to comment Share on other sites More sharing options...
dminder Posted April 9, 2010 Author Share Posted April 9, 2010 It doesn't like this line:$h = new http(); Do you have a class constructor called http() ? Do you need to include a file to access it? Were you thinking of some other built-in object support? There is an HttpRequest object in PHP 5 and newer. It doesn't have a fetch method, however. Yeah there is apparently an additional class needed, which is not supplied. SOOO i am back to the drawing board, but it looks like I can do this another way. Thanks guys! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.