strpos - Merging numbered lists in PHP -


i have set of items numbers assigned them , trying fill in gaps person before me left in spreadsheet. figured write php script me yet it's placing assigned numbers in weird spots.

here's example:

i have associative array of numbers / names

[0] => 3502 "scallops, bay" [1] => 3503 "oysters, chesepeake" [2] => 3504 "clams, cherry stone" 

the script order these is:

$d = file("list.txt"); $j=0; ($i=2000;$i<8000;$i++) {  //i want codes begin @ 2000 , end @ 8000     if (strpos($d[$j], $i) !== false) {         echo $d[$j]."<br/>";         $j++;     } else {         echo $i."<br/>";     } } 

but here's i'm getting:

2000-2056 print out fine, because don't match [0] of $d, on 2057 prints

2056 3502    "scallops, bay"  3503    "oysters, chesepeake" 2059 2060 3504    "clams, chery stone"  

then goes print on until 2080 prints [3] of $d.

i'm confused. don't see 2057 anywhere in "3502 'scallops, bay'"

should trying different approach?

the second argument strpos() can integer or string; if it's integer, it's ordinal value used search. manual:

if needle not string, converted integer , applied ordinal value of character.

you should cast index string first:

if (strpos($d[$j], "$i") !== false) { 

btw, better check whether line starts $i , whether $d[$j] still valid entry:

if (isset($d[$j]) && strpos($d[$j], "$i\t") === 0) { 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -