Jump to content

Recommended Posts

<?

// standings space delimited file 
$file = "stn/standings.stn"; 

// open file 
$handle = fopen($file, "rb");
$contents = fread($handle, filesize($file));

// close file, read everything in between spaces
// omitting the first section header and also
// make sure we replace the new line marker 
fclose($handle);
$contents = preg_replace ('/<TD\s+style="background\s+:\s+#CEDAEB">\r?\n|\r/i','', $contents);
$contents = preg_replace ('/<\/TD>\r?\n|\r/i','', $contents);
$contents = preg_replace ('/<TR\s+style="color\s+:\s+black">\r?\n|\r/i','', $contents);
$contents = preg_replace ('/<!DOCTYPE\s+HTML.*?Qualifying/is','', $contents);
$data = preg_split("/\r?\n|\r/", $contents);
$remove = array("\n", "\r\n", "\r");
$data = str_replace($remove, ' ', $data); 

$drivername = "B Pack";
$key = array_search($drivername, $data);
echo $key;


?>

 

The echo returns nothing, but if I change it to a number, the echo returns a key number.  The array has both numbers and name strings.  I can't figure out what I am doing wrong? Thank you for your help in advance!

Link to comment
https://forums.phpfreaks.com/topic/199611-array_search-issues/
Share on other sites

Are you sure that "B Pack" is in the data? 

 

Maybe it is there are "B Pack " -- particularly since you replaced the newlines with a space, change your str_replace to replace with nothing:

$data = str_replace($remove, ' ', $data);
// change that line to this
$data = str_replace($remove, '', $data);

 

see if that works.

Link to comment
https://forums.phpfreaks.com/topic/199611-array_search-issues/#findComment-1047735
Share on other sites

That didn't work unfortunately, when I print the array I get this:

 

B Pack is at array #16

 

Array ( [0] => [1] => [2] =>
[3] => style="background : #173D54" [5] => cellpadding="3" [6] => cellspacing="2" [7] => summary=""> [8] => P [9] => # [10] => DRIVER [11] => TIME [12] => [13] => 1 [14] => 81 [15] => B Pack [16] => 169.918 mph [17] => 2 [18] => 29 [19] => Jeff E [20] => 169.396 mph [21] => 3 [22] => 5 [23] => C Pasteryak [24] => 169.194 mph [25] => 4 [26] => 25 [27] => M Leaty [28] => 168.508 mph [29] => 5 [30] => 21 [31] => K Barry [32] => 168.366 mph [33] => 6 [34] => 6 [35] => J Leaty [36] => 168.361 mph [37] => 7 [38] => 51 [39] => Jeff F [40] => 168.298 mph [41] => 8 [42] => 99 [43] => J Tomaino [44] => 168.235 mph [45] => 9 [46] => 3 [47] => E Beers [48] => 168.193 mph [49] => 10 [50] => 60 [51] => M Hirschman [52] => 168.177 mph [53] => 11 [54] => 14 [55] => B Hutchens [56] => 168.104 mph [57] => 12 [58] => 88 [59] => J Civali [60] => 168.078 mph [61] => 13 [62] => 48 [63] => T Hirschman [64] => 168.078 mph [65] => 14 [66] => 9 [67] => E Beers [68] => 168.067 mph [69] => 15 [70] => 38 [71] => C Kuzma [72] => 167.999 mph [73] => 16 [74] => 69 [75] => J Miller [76] => 167.858 mph [77] => 17 [78] => 66 [79] => P Brittain [80] => 167.832 mph [81] => 18 [82] => 2 [83] => T Szegedy [84] => 167.827 mph [85] => 19 [86] => 10 [87] => E Flemke, Jr. [88] => 167.791 mph [89] => 20 [90] => 18 [91] => D Lia [92] => 167.749 mph [93] => 21 [94] => 8 [95] => Jeff G [96] => 167.614 mph [97] => 22 [98] => 12 [99] => J Blewett [100] => 167.593 mph [101] => 23 [102] => 83 [103] => T Brown [104] => 167.541 mph [105] => 24 [106] => 00 [107] => R Fuller [108] => 167.473 mph [109] => 25 [110] => 44 [111] => R Ruggiero [112] => 167.421 mph [113] => 26 [114] => 7 [115] => J Yeley [116] => 167.385 mph [117] => 27 [118] => 41 [119] => R Ruggiero [120] => 167.385 mph [121] => 28 [122] => 15 [123] => Z Sylvester [124] => 167.364 mph [125] => 29 [126] => 22 [127] => Jeff H [128] => 167.235 mph [129] => 30 [130] => 23 [131] => B Loftin [132] => 166.708 mph [133] => 31 [134] => 4 [135] => J Myers [136] => 166.687 mph [137] => 32 [138] => 34 [139] => M Mulhall [140] => 166.621 mph [141] => 33 [142] => 36 [143] => L Miller [144] => 166.569 mph [145] => 34 [146] => 1 [147] => B Myers [148] => 166.492 mph [149] => 35 [150] => 20 [151] => J Stoltz [152] => 166.374 mph [153] => 36 [154] => 28 [155] => J Civali [156] => 166.323 mph [157] => 37 [158] => 43 [159] => K Alexander [160] => 166.190 mph [161] => 38 [162] => 55 [163] => J Doucette [164] => 166.180 mph [165] => 39 [166] => 16 [167] => M Stefanik [168] => 166.149 mph [169] => 40 [170] => 07 [171] => F Fleming [172] => 165.812 mph [173] => 41 [174] => 17 [175] => B King [176] => 165.244 mph [177] => 42 [178] => 77 [179] => S [180] => 164.564 mph [181] => 43 [182] => 31 [183] => G Pack [184] => 164.434 mph [185] => 

Link to comment
https://forums.phpfreaks.com/topic/199611-array_search-issues/#findComment-1047817
Share on other sites

I want to thank you for leading me in the right direction I figured it out.  In the output file there is a tab placed before each one of the values.  I needed to get rid of it by putting this line underneath the other regex functions:

 

$contents = preg_replace ('/\t/is','', $contents);

 

Thank you!

Link to comment
https://forums.phpfreaks.com/topic/199611-array_search-issues/#findComment-1047833
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.