Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7946139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:03:47+00:00 2026-06-04T01:03:47+00:00

I copied some PHP I wrote a while back to scrub addresses. In the

  • 0

I copied some PHP I wrote a while back to scrub addresses. In the original page, it lives on a live webserver and works perfectly. The current script runs from the command line on my development machine. the CLI script always throws ‘index not defined’ errors, but the index is defined, from this code:

$url = 'http://production.shippingapis.com/ShippingAPI.dll?API=ZipCodeLookup&XML=';
$msg = '
<ZipCodeLookupRequest USERID="xxxxxxxxxx">
<Address ID="0"><FirmName></FirmName><Address1>' . $suite . '</Address1>
<Address2>' . $street . '</Address2>
<City>' . $city . '</City><State>' . $state . '</State>
</Address></ZipCodeLookupRequest>
';

//get the response from the USPS
$newurl = $url . urlencode($msg);

// echo $newurl;

$xml    = $newurl;
$parser = xml_parser_create();

// open a file and read data
$fp      = fopen($xml, 'r');
$xmldata = fread($fp, 4096);

xml_parse_into_struct($parser, $xmldata, $values);

xml_parser_free($parser);
//echo $xmldata;
//print_r($values);

if ($values[6][tag] === 'ZIP4') {
    $street = $values[2][value];
    $city   = $values[3][value];
    $state  = $values[4][value];
    $zip5   = $values[5][value];
    $zip4   = $values[6][value];
}
else if ($values[7][tag] === 'ZIP4') {
    $suite  = $values[2][value];
    $street = $values[3][value];
    $city   = $values[4][value];
    $state  = $values[5][value];
    $zip5   = $values[6][value];
    $zip4   = $values[7][value];
}
else {
    $suite  = '';
    $street = '';
    $city   = '';
    $state  = '';
    $zip5   = '';
    $zip4   = '';
}
;

if ($values[2][tag] != 'ERROR') {
    $verifiedBlock = ("
    $suite . chr(13) . chr(10);
    $street . chr(13) . chr(10);
    $city $state $zip5 $zip4
    ");
}
else {
    $verifiedBlock = ("
    The address could not be verified
    ");
}
;

If I do a print_r of $values, I get back this:

Array (    [0] => Array
       (
           [tag] => ZIPCODELOOKUPRESPONSE
           [type] => open
           [level] => 1
       )

   [1] => Array
       (
           [tag] => ADDRESS
           [type] => open
           [level] => 2
           [attributes] => Array
               (
                   [ID] => 0
               )

       )

   [2] => Array
       (
           [tag] => ADDRESS1
           [type] => complete
           [level] => 3
           [value] => FL 7
       )

etc – I have confirmed that [6] and [7] always exist. Yet, always it throws ‘index not defined’ errors on these lines and the if ($values[2][tag] != 'ERROR') line.

Can someone please tell me what stupid, obvious thing I’m missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:03:49+00:00Added an answer on June 4, 2026 at 1:03 am

    In your code I see $values[2][tag].In this context tag is a constant that must not be defined. You’ve got key tag that is a string, so you have to use it as string, e.g. $values[2]['tag']. Oh, and do the same thing with other indexes (keys).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I copied some PHP mailer and at some point had it working. But the
I have copied some files from project A to project B, both of which
I coded some calculation stuff (I copied below a really simplifed example of what
I have some 3rd party libraries and includes (I have copied them to the
I am processing some CSV file which i have copied in Bin folder of
I've got an application where some assemblies are copied to C:\Windows\assembly upon deployment under
I'm working on some doc file, that when copied and pasted into a text
some code snippets. The java coding doing the jaxb unmarshaling. pretty straightforward, copied out
Every day in my server are copied some images via ftp.I want for every
I am using PHP to generate some XML. I need to put quotes in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.