ashutoash Posted November 7, 2011 Share Posted November 7, 2011 I am trying to display rows starting with a specific tag when using fgetcsv() like rows starting with tag SY or AP where the first element of each such rows would have SY or AP has prefix example SY-Atlanta, SY-Texas, AP-Atlanta, AP-texas. The next columns in that row would have some data. I want to display only rows with above said prefix. What is the best way to do it? Use preg_match for each row and display it only if it has a match or is there any easier way? Sample data in csv: SY-Atlanta,0,0,0,5,9,9,0 SY-Texas,0,5,8,0,0,8.4 AP-Atlanta,9,4,8,9,0,0,0 AP-Texas,8,0,9,0,0,0,0 DF-Atlanta,8,4,9,3,0,0,0,0 DF-Texas,8,4,9,0,0,0,0,0 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 7, 2011 Share Posted November 7, 2011 strpos should be faster than preg_match. Directly testing the first two elements of the string holding the data using - $string[0] and $string[1], might even be faster. Quote Link to comment Share on other sites More sharing options...
ashutoash Posted November 7, 2011 Author Share Posted November 7, 2011 Thanks. I used both and could not even tell if there was time difference. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.