Undefined offset error

Ok so you don’t actually know the number of keys correct?

I’m not sure if it’s even necessary to use preg_split I think you could probably preg_match what you need. However… what if you did something like this instead.

[php]
while(($buffer = fgets($fh, 4096)) !== false) {
$kvp = preg_split ("/[\s,]+/", $buffer);
$index = array_shift($kvp); // shift the first element to use as array index
$results[$index] = implode(" ", $kvp); // implode remaining elements
}
[/php]

Interesting but, HTML out has no error while UNIX output does
//// Here’s the script ////////////////

[php] //PHP Code: [Select] by w@tt 7 Mar. '13
echo 'L.3 watt_test.php ’ . date('l dS \of F Y h:i:s A ’ . ‘

’);

include_once ($_SERVER{'DOCUMENT_ROOT'} . '/.../SMTP4PHP.php');

$results = array();

try {

$fh = @fopen($_SERVER{‘DOCUMENT_ROOT’} . ‘/…/kvpisow2.txt’, “r”);

while(($buffer = fgets($fh, 4096)) !== false) {	
	$kvp = preg_split ("/[\s,]+/", $buffer);	
	$index = array_shift($kvp); 			// shift the first element to use as array index
	$results[$index] = implode(" ", $kvp); 	// implode remaining elements
	
	//$results[$kvp[1]] = $kvp[3] . " " . $kvp[4] . " " . $kvp[5] . " " . $kvp[6] . " " . $kvp[7] . " " . $kvp[8];
	}		

fclose($fh);

}

catch(Exception $e) {

exit('Exception caught: ’ . $e->getMessage());
}
var_dump($results);
[/php]

////////// Here’s the HTML output ////////////////////
L.3 watt_test.php Friday 08th of March 2013 08:51:08 AM
array(1) { [“Key”]=> string(18) “ZI Value Zimbabwe " } // //if ($fh) { // // while(($buffer = fgets($fh, 4096)) !== false) { // // $kvp = preg_split (”/[\s,]+/", $buffer); // // $results[$kvp[1]] = $kvp[3] . " " . $kvp[4] . " " . $kvp[5] . " " . $kvp[6] . " " . $kvp[7] . " " . $kvp[8]; // // }

//////////// and here’s the UNIX output w/ its error mssg ////////////

u-sit@lsh1001:~/…b/usit2013$ php watt_test.php;
L.3 watt_test.php Friday 08th of March 2013 08:50:02 AM

PHP Warning: include_once(/…/SMTP4PHP.php): failed to open stream: No such file or directory in /…/usit2013/watt_test.php on line 4
PHP Warning: include_once(): Failed opening ‘/…/SMTP4PHP.php’ for inclusion (include_path=’.:/usr/share/php:/usr/share/pear’) in /…/watt_test.php on line 4
PHP Warning: fgets() expects parameter 1 to be resource, boolean given in /…/watt_test.php on line 11
PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /…/watt_test.php on line 19
array(0) {
}

w@tt,
I hope these posts are understandable. I’ve yet to master this entry system using this live input window. It quickly becomes unstable and I can’t keep up with what needs editing. So I’ve resorted to doing everything in WORD and then transferring the whole thing into the live window. That leaves the problem of findinding the script and enclosing it in tags.
usit

Just read the error it tells you what the problem is.

include_once(/.../SMTP4PHP.php): failed to open stream: No such file or directory

So the SMTP4PHP.php file is missing. Did you use a different directory this time?

The kvpisow2.txt file is likely also missing that’s why you get fgets errors. If you kept the if ($fh) you wouldn’t get these but it still wouldn’t work.

Yes, I saw the error and immediately kicked myself. The file called, STP4PHP.php, is used in smtp calls but now in this snippet.
I really apologize for sending it to you the last post with the unnecessary line of code.
Your script seemed to be working on my PC, so I took a fresh segment from the main program, inserted your script into it as shown here …
============ GRS06sgmnt.php ========================================

<?php //RGS06sgmnt.php echo 'L.3 RGS06sgmnt.php ' . date('l dS \of F Y h:i:s A ' . '

'); $a = Array(); // array will be for country choice options and their 2-char codes $a[" "] = ''; // first element is blank - forces user to select one $fh = fopen("http://www.../kvpisow2.txt", "r"); // List of country names: KEY CHAR(2-char) VALUE CHAR('<=6word name') "kvpisow2.txt", "r" while(($buffer = fgets($fh, 4096)) !== false) { $kvp = preg_split ("/[\s,]+/", $buffer); var_dump($buffer); $index = array_shift($kvp); // shift the first element to use as array index $results[$index] = implode(" ", $kvp); // implode remaining elements $results[$kvp[1]] = $kvp[3] . " " . $kvp[4] . " " . $kvp[5] . " " . $kvp[6] . " " . $kvp[7] . " " . $kvp[8]; } fclose ($fh); ?>

=================== end ============================
It produces no HTML errors in the following output showing each array element being the appropriate string.
========== HTML output ==============================
L.3 RGS06sgmnt.php Friday 08th of March 2013 03:24:18 PM
string(28) "Key US Value United States " string(26) "Key AF Value Afghanistan " string(22) "Key AL Value Albania " string(22) "Key AG Value Algeria " string(22) "Key AN Value Andorra " string(21) "Key AO Value Angola " string(34) "Key AC Value Antigua and Barbuda " string(24) "Key AR Value Argentina " string(24) "Key AS Value Australia " string(22) "Key AU Value Austria " string(25) "Key AJ Value Azerbaijan " string(27) "Key BF Value Bahamas, The " string(22) "Key BA Value Bahrain " string(25) "Key BG Value Bangladesh " string(23) "Key BB Value Barbados " string(22) "Key BO Value Belarus " string(22) "Key BE Value Belgium " string(21) "Key BH Value Belize " string(20) "Key BN Value Benin " string(21) "Key BT Value Bhutan " string(22) "Key BL Value Bolivia " string(37) "Key BK Value Bosnia and Herzegovina " string(23) "Key BC Value Botswana " string(21) "Key BR Value Brazil " string(21) "Key BX Value Brunei " string(23) "Key BU Value Bulgaria " string(27) "Key UV Value Burkina Faso " string(20) "Key BM Value Burma " string(22) "Key BY Value Burundi " string(23) "Key CB Value Cambodia " string(23) "Key CM Value Cameroon " string(21) "Key CA Value Canada " string(25) "Key CV Value Cape Verde " string(39) "Key CT Value Central African Republic " string(19) "Key CD Value Chad " string(20) "Key CI Value Chile " string(20) "Key CH Value China " string(23) "Key CO Value Colombia " string(22) "Key CN Value Comoros " string(34) "Key CF Value Congo (Brazzaville) " string(31) "Key CG Value Congo (Kinshasa) " string(25) "Key CS Value Costa Rica " string(29) "Key IV Value Côte d’Ivoire " string(22) "Key HR Value Croatia " string(19) "Key CU Value Cuba " string(21) "Key CY Value Cyprus " string(29) "Key EZ Value Czech Republic " string(22) "Key DA Value Denmark " string(23) "Key DJ Value Djibouti " string(23) "Key DO Value Dominica " string(33) "Key DR Value Dominican Republic " string(22) "Key EC Value Ecuador " string(20) "Key EG Value Egypt " string(26) "Key ES Value El Salvador " string(32) "Key EK Value Equatorial Guinea " string(22) "Key ER Value Eritrea " string(22) "Key EN Value Estonia " string(23) "Key ET Value Ethiopia " string(19) "Key FJ Value Fiji " string(22) "Key FI Value Finland " string(21) "Key FR Value France " string(20) "Key GB Value Gabon " string(26) "Key GA Value Gambia, The " string(22) "Key GG Value Georgia " string(22) "Key GM Value Germany " string(20) "Key GH Value Ghana " string(21) "Key GR Value Greece " string(22) "Key GJ Value Grenada " string(24) "Key GT Value Guatemala " string(21) "Key GV Value Guinea " string(28) "Key PU Value Guinea-Bissau " string(21) "Key GY Value Guyana " string(20) "Key HA Value Haiti " string(23) "Key VT Value Holy See " string(23) "Key HO Value Honduras " string(22) "Key HU Value Hungary " string(22) "Key IC Value Iceland " string(20) "Key IN Value India " string(24) "Key ID Value Indonesia " string(19) "Key IR Value Iran " string(19) "Key IZ Value Iraq " string(22) "Key EI Value Ireland " string(21) "Key IS Value Israel " string(20) "Key IT Value Italy " string(22) "Key JM Value Jamaica " string(20) "Key JA Value Japan " string(21) "Key JO Value Jordan " string(25) "Key KZ Value Kazakhstan " string(20) "Key KE Value Kenya " string(23) "Key KR Value Kiribati " string(27) "Key KN Value Korea, North " string(27) "Key KS Value Korea, South " string(21) "Key KU Value Kuwait " string(25) "Key KG Value Kyrgyzstan " string(19) "Key LA Value Laos " string(21) "Key LG Value Latvia " string(22) "Key LE Value Lebanon " string(22) "Key LT Value Lesotho " string(22) "Key LI Value Liberia " string(20) "Key LY Value Libya " string(28) "Key LS Value Liechtenstein " string(24) "Key LH Value Lithuania " string(25) "Key LU Value Luxembourg " string(57) "Key MK Value Macedonia, The Former Yugoslav Republic of " string(25) "Key MA Value Madagascar " string(21) "Key MI Value Malawi " string(23) "Key MY Value Malaysia " string(23) "Key MV Value Maldives " string(19) "Key ML Value Mali " string(20) "Key MT Value Malta " string(31) "Key RM Value Marshall Islands " string(25) "Key MR Value Mauritania " string(24) "Key MP Value Mauritius " string(21) "Key MX Value Mexico " string(46) "Key FM Value Micronesia, Federated States of " string(22) "Key MD Value Moldova " string(21) "Key MN Value Monaco " string(23) "Key MG Value Mongolia " string(22) "Key MO Value Morocco " string(25) "Key MZ Value Mozambique " string(22) "Key WA Value Namibia " string(20) "Key NR Value Nauru " string(20) "Key NP Value Nepal " string(26) "Key NL Value Netherlands " string(26) "Key NZ Value New Zealand " string(24) "Key NU Value Nicaragua " string(20) "Key NG Value Niger " string(22) "Key NI Value Nigeria " string(21) "Key NO Value Norway " string(19) "Key MU Value Oman " string(23) "Key PK Value Pakistan " string(20) "Key PS Value Palau " string(21) "Key PM Value Panama " string(31) "Key PP Value Papua New Guinea " string(23) "Key PA Value Paraguay " string(19) "Key PE Value Peru " string(26) "Key RP Value Philippines " string(21) "Key PL Value Poland " string(23) "Key PO Value Portugal " string(20) "Key QA Value Qatar " string(22) "Key RO Value Romania " string(21) "Key RS Value Russia " string(21) "Key RW Value Rwanda " string(36) "Key SC Value Saint Kitts and Nevis " string(26) "Key ST Value Saint Lucia " string(47) "Key VC Value Saint Vincent and the Grenadines " string(20) "Key WS Value Samoa " string(25) "Key SM Value San Marino " string(36) "Key TP Value Sao Tome and Principe " string(27) "Key SA Value Saudi Arabia " string(22) "Key SG Value Senegal " string(25) "Key SE Value Seychelles " string(27) "Key SL Value Sierra Leone " string(24) "Key SN Value Singapore " string(23) "Key LO Value Slovakia " string(23) "Key SI Value Slovenia " string(30) "Key BP Value Solomon Islands " string(22) "Key SO Value Somalia " string(27) "Key SF Value South Africa " string(20) "Key SP Value Spain " string(24) "Key CE Value Sri Lanka " string(20) "Key SU Value Sudan " string(23) "Key NS Value Suriname " string(24) "Key WZ Value Swaziland " string(21) "Key SW Value Sweden " string(26) "Key SZ Value Switzerland " string(20) "Key SY Value Syria " string(21) "Key TW Value Taiwan " string(25) "Key TI Value Tajikistan " string(23) "Key TZ Value Tanzania " string(23) "Key TH Value Thailand " string(19) "Key TO Value Togo " string(20) "Key TN Value Tonga " string(34) "Key TD Value Trinidad and Tobago " string(22) "Key TS Value Tunisia " string(21) "Key TU Value Turkey " string(27) "Key TX Value Turkmenistan " string(21) "Key TV Value Tuvalu " string(21) "Key UG Value Uganda " string(22) "Key UP Value Ukraine " string(35) "Key TC Value United Arab Emirates " string(29) "Key UK Value United Kingdom " string(22) "Key UY Value Uruguay " string(25) "Key UZ Value Uzbekistan " string(22) "Key NH Value Vanuatu " string(24) "Key VE Value Venezuela " string(22) "Key VM Value Vietnam " string(20) "Key YM Value Yemen " string(25) "Key YI Value Yugoslavia " string(21) "Key ZA Value Zambia " string(23) "Key ZI Value Zimbabwe "
============= end HTML =======================
The following is a sample of UNIX output. A couple hundred lines of offset errors at the same location as usual:
============= UNIX ==========================
string(22) "Key SO Value Somalia
"
PHP Notice: Undefined offset: 4 in /home/vg011web00/68/65/2926568/web/auxlib/usit2013/RGS06sgmnt.php on line 23
PHP Notice: Undefined offset: 5 in /home/vg011web00/68/65/2926568/web/auxlib/usit2013/RGS06sgmnt.php on line 23
PHP Notice: Undefined offset: 6 in /home/vg011web00/68/65/2926568/web/auxlib/usit2013/RGS06sgmnt.php on line 23
PHP Notice: Undefined offset: 7 in /home/vg011web00/68/65/2926568/web/auxlib/usit2013/RGS06sgmnt.php on line 23
PHP Notice: Undefined offset: 8 in /home/vg011web00/68/65/2926568/web/auxlib/usit2013/RGS06sgmnt.php on line 23
string(27) "Key SF Value South Africa
"
PHP Notice: Undefined offset: 5 in /home/vg011web00/68/65/2926568/web/auxlib/usit2013/RGS06sgmnt.php on line 23
PHP Notice: Undefined offset: 6 in /home/vg011web00/68/65/2926568/web/auxlib/usit2013/RGS06sgmnt.php on line 23
PHP Notice: Undefined offset: 7 in /home/vg011web00/68/65/2926568/web/auxlib/usit2013/RGS06sgmnt.php on line 23
PHP Notice: Undefined offset: 8 in /home/vg011web00/68/65/2926568/web/auxlib/usit2013/RGS06sgmnt.php on line 23
string(20) "Key SP Value Spain
"
================ end UNIX =========================================

Why did you put the old code back in there?

[php]$results[$kvp[1]] = $kvp[3] . " " . $kvp[4] . " " . $kvp[5] . " " . $kvp[6] . " " . $kvp[7] . " " . $kvp[8];[/php]

This code will never work.

I was testing your code in a small segment of the main and it seemed to work. So I went back to the main and substituted your code for the part not working. I put in on the line above a line that should have been commented out. It wasn’t in the tests because I was comparing the difference w/ and w/o that line. Hence, mia culpa again! And again I’m sorry for this oversight and its nuisance.

I’ve gone ahead and inserted your code in the main to see what happens. Unfortunately, the main now fails before getting to this repaired segment. The failure is the same as it was two weeks ago …

Fatal error: Uncaught exception ‘ErrorException’ with message ‘Undefined index: invoiceNo’ in /home/…/RGSTRTN_06.php:97 Stack trace: #0 /home/…/RGSTRTN_06.php(97): exception_error_handler(8, ‘Undefined index…’, ‘/home/vg011web0…’, 97, Array) #1 {main} thrown in /home/v…/RGSTRTN_06.php on line 97

I’m back to work on that error now to see if I’ve learned enough to solve it myself. Should I close this thread or wait to see if this error becomes intractable for me and I have to ask for help again?

Your expertise is greatly appreciated.
THanks again,

usit

Two questions for w@tt:

  1. Your scritp …
    [php] while(($buffer = fgets($fh, 4096)) !== false) {
    $kvp = preg_split ("/[\s,]+/", $buffer); $index = array_shift($kvp); // shift the first element to use as array index $results[$index] = implode(" ", $kvp); // implode remaining elements}[/php]

(Must have pushed wrong button and lost my reply window. Here goes again.)

Question for w@tt:

  1. In your script fgets() puts the correct array into $buffer but skips the first entry (key US value United States). I don’t understand why. It doesn’t throw an error. The remainder of the array is reconstructed in the next two commands but, again, w/o the first entry.

[php]while(($buffer = fgets($fh, 4096)) !== false) {
$kvp = preg_split ("/[\s,]+/", $buffer);
$index = array_shift($kvp); // shift the first element to use as array index
$results[$index] = implode(" ", $kvp); // implode remaining elements}
[/php]

usit

Please post your current (full) code again

Here’s the front end w/o a bunch of extraneous stuff (the entire 800+ lines are available is needed for any reason)
[php] // /RGSTRTN_06_snip2.php

$counter = file_get_contents($_SERVER['DOCUMENT_ROOT'] .'/auxlib/usit2013/counter.txt'); 
$counter++; file_put_contents("counter.txt", $counter); 

include_once ($_SERVER['DOCUMENT_ROOT'] . '/.../cnnct2mysql.php');
include_once ($_SERVER{'DOCUMENT_ROOT'} . '/.../usit2013/SMTP4PHP.php');
error_reporting (E_ALL ^ E_NOTICE); 	

$time_stamp 	=  date('l dS \of F Y h:i:s A ');
echo $counter,  '    RGSTRTN_06.php ' . date('l dS \of F Y h:i:s A '),'<p>';			

?>

headers <?PHP $fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
//////////////////////////////////////////////////////////////////////////
//	 A. Assign self-posted REGISTRATION data to local variables.	//
//////////////////////////////////////////////////////////////////////////

echo "L.65 ",   $tried ? "  tried is set <p>" : "  tried is not set <p>";

if($tried == true) //Set to yes when registration form is submitted (at end of this script L. 778)
{
$invoiceNo = $_POST[‘invoiceNo’];
$amount = $_POST[‘amount’];
$item_name = $_POST[‘item_name’];
$email = $_POST[‘email’];
// abbreviated list of client registration data
}
//////////////////////////////////////////////////////////////////////////
// B. Prepare Country- & State-select tags (Courtesy David Kirol) //
// (array processing courtesy w@tt, PHP Help Forum) //
//////////////////////////////////////////////////////////////////////////

$a 	= Array();	
$a[" "] = '';		
$fh = fopen("http://www.u-sit.net/.../kvpisow2.txt", "r");

while(($buffer = fgets($fh, 4096)) !== false) 
	{	
	$kvp = preg_split ("/[\s,]+/", $buffer);
	$index = array_shift($kvp); 			// shift the first element to use as array index
	$results[$index] = implode(" ", $kvp); 	
	}
fclose ($fh);	
////////////////////  ++++++++++++++ End of Country prep  +++++++++++++ ////////////////

$b = Array();	
$b[" "] = '';
$gh = fopen($_SERVER{'DOCUMENT_ROOT'} . '/.../StateCodes.txt', "r");	
$results = array();

while (($buffer = fgets($gh)) !== false) 
	{
	$ens = preg_split ("/[\s,]+/", $buffer); 	// Split buffer on any combination of spaces or commas.
	$index = array_shift($ens);
	$results[$index] = implode(" ", $ens);
    }                    	 
fclose ($gh);	
///////////////  ++++++++++   End Country- & State-array preparations.  +++++++++++++++++++++ //

$tried = $_POST['tried'] == 'yes';

/*
IF ($tried) {
*/
//////////////////////////////////////////////////////////////////////////////////////////
// C. Echo self-posted data for customer’s information w/o allowing corrections. //
//////////////////////////////////////////////////////////////////////////////////////////
[/php]

It could be because you don’t define $results before the while loop.

[php]
$results = array();
[/php]

I also noticed you are using $results again on the second while loop. Do you intend to overwrite that array?

w@tt, I thought I had it, then, this result – array() has only the last key/value pair this time! I’ve screwed up some how.
[php]echo 'L.2 watt_test3.php ’ . date('l dS \of F Y h:i:s A ’ . ‘

’);
$results = array();
try {
$fh = fopen(“http://www.u-sit.net/auxlib/web07/InclReq/kvpisow2.txt”, “r”);
if ($fh)
{
while(($buffer = fgets($fh, 4096)) !== false)
{
$kvp = preg_split ("/[\s,]+/", $buffer);
$index = array_shift($kvp);
$results[$index] = implode(" ", $kvp);
}
}
fclose($fh);
}
catch(Exception $e)
{
exit('Exception caught: ’ . $e->getMessage());
}var_dump($results);
//No error but $results has only the last key/value pair: array(1) { [“Key”]=> string(18) "ZI Value Zimbabwe " }
[/php]
usit

Well that is because every $index = ‘Key’ so it will continuously overwrite instead of creating a new index.

Try this code and let me know if this is what you’re looking for.

[php]
$results = array();
try {
$fh = @fopen(“http://www.u-sit.net/auxlib/web07/InclReq/kvpisow2.txt”, “r”);
if ($fh) {
while(($buffer = fgets($fh, 4096)) !== false) {
if (preg_match(’/^Key\s([A-Z]+)\sValue\s(.)$/’, $buffer, $kvp)) {
/

$kvp is now an array like this:

			array (size=3)
			  0 => string 'Key US Value United States ' (length=27)
			  1 => string 'US' (length=2)
			  2 => string 'United States ' (length=14)				
			*/
			$results[$kvp[1]] = $kvp[2];
		}
	}
}
fclose($fh);

}
catch(Exception $e) {
exit('Exception caught: ’ . $e->getMessage());
}
var_dump($results);
[/php]

w@tt, Made a change that resolved the problem.
usit

I’ve done it now! Doubled your script to use in main, but first wrapped it in php tags and ran a test.
It executes the first copy correctly but produces an empty $b() array in the second?
[php] // B. Prepare Country- & State-select tags (Courtesy David Kirol) //
// (processing courtesy w@tt, PHPHelp Forum) //

$a = array();
$b = array();
try
{
$fh = @fopen($_SERVER{‘DOCUMENT_ROOT’} . ‘/auxlib/web07/InclReq/kvpisow2.txt’, “r”);
if ($fh){
while(($buffer = fgets($fh, 4096)) !== false)
{
if (preg_match(’/^Key\s([A-Z]+)\sValue\s(.*)$/’, $buffer, $kvp))
{
$a[$kvp[1]] = $kvp[2];
}
}
}
fclose($fh);

$gh = @fopen($_SERVER{'DOCUMENT_ROOT'} . '/auxlib/web07/InclReq/StateCodes.txt', "r");	
if ($gh){				
		while(($buffer = fgets($gh, 4096)) !== false)
			{
			  if (preg_match('/^Key\s([A-Z]+)\sValue\s(.*)$/', $buffer, $ens))
				{			
				$b[$ens[1]] = $ens[2];
				}
			}
		}
fclose($gh);	

}

catch(Exception $e)
{
exit(‘Exception caugght:’ . $e->getMessage());
}
echo “

” , var_dump($a) , “

”;
echo “

” , var_dump($b) , “

”;
[/php]
Can you make any sense of this outcome?

The format is different in the second text file. You would need to use “name” instead of “Key”

[php]’/^name\s([A-Z]+)\svalue\s(.*)$/’[/php]

w@tt, as usual, your astute insights are very enlightning. I think we’re almos there now. Here’s were things stand.

  1. Took code|country and code|state sections out of main, wrapped them in [php][/php] tags, inserted some ‘echo’ and ‘var-dump’ lines to enable watching where things change. Results:
    1a. Using Key|value in country section and name|value in state section, array $a() has the desired country|code pairs but, $b() is empty(?)
    1b. However, prior to the preg_match() operation $buffer2 has the needed state|code pairs. I can’t figure out where they went after the preg_match step. Here’s the test script …

[php] //watt_test4.php 17Mar’13
// (processing courtesy w@tt, PHPHelp Forum) //

echo 'watt_test4.php   ' . date('l dS \of F Y h:i:s A '),'<p>';

$a = array();
$b = array();

$fh = @fopen($_SERVER{'DOCUMENT_ROOT'} . '/auxlib/web07/InclReq/kvpisow2.txt', "r");
if ($fh){				
		while(($buffer1 = fgets($fh, 4096)) !== false)
			{  echo 'L12 \$bufffer1 = ', $buffer1;
			  if (preg_match('/^Key\s([A-Z]+)\sValue\s(.*)$/', $buffer1, $kvp))
				{	echo 'L14    \$bufffer1 = ', $buffer1;		
				$a[$kvp[1]] = $kvp[2];
				}
			}
		}
fclose($fh);

echo “

”;
echo "

L21 var_dump($a) =

" , var_dump($a) , “

”;
echo “

”;
//------------------------------------------------------------------------------------//
$gh = @fopen($_SERVER{‘DOCUMENT_ROOT’} . ‘/auxlib/web07/InclReq/StateCodes.txt’, “r”);

if ($gh){				
		while(($buffer2 = fgets($gh, 4096)) !== false)
			{  echo 'L28 \$bufffer2 = ', $buffer2;
			  if (preg_match('/^Name\s([A-Z]+)\sValue\s(.*)$/', $buffer2, $ens))
				{	echo '    L30 \$bufffer2 = ', $buffer2;		
				$b[$ens[1]] = $ens[2];
				}
			}
		}
fclose($gh);	

//echo "

L36 $buffer2 = " , $buffer2, “

”;
echo "

L37 $b = var_dump($b)

" , var_dump($b) , “

”;
[/php]

‘name’ is lowercase in your StateCodes.txt

You could try adding ‘i’ to the end for case-insensitive search.

[php]’/^Name\s([A-Z]+)\sValue\s(.*)$/i’[/php]

Note that you could also apply trim() to your value if you want to remove the trailing whitespaces. e.g.

[php]$results[$kvp[1]] = trim($kvp[2]);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service