mkosmosports Posted April 23, 2007 Share Posted April 23, 2007 Hello, Ive got a file which contains the following data: <option value="13">African Nations Cup XXV</option> <option value="16">asd</option> <option value="7">Champions League</option> <option value="1">English Premiership</option> What Id like to do is get the maximum value, so 16. Ive used file_get_contents to bring the file into a string, but now Im stuck getting that max value out. Unless theres a function for this, I believe the direction I would need to take is collect all value numbers using some string manipulation function, throw them all into an array, and just get the max value of the array. Is there an easier way? If someone could point me in the right direction I would appreciate it... Thanks! Quote Link to comment Share on other sites More sharing options...
dsaba Posted April 23, 2007 Share Posted April 23, 2007 only way i could think of how to do this is: 1. you have to already know what the max number is your looking for you reference or look it up somewhere, maybe you can look it up or store it in your database, if this data is coming from there anyways 2. then you just strpos() find '<option value="'.$maxnumber.'">' Quote Link to comment Share on other sites More sharing options...
mkosmosports Posted April 23, 2007 Author Share Posted April 23, 2007 Hey dsaba, Unfortunately I dont know that value beforehand. I do have that number in a database, so I can take it out from there anytime, however, my script creates this file in its beginning stages, and since the file already contains the information Im looking for, Im hoping theres a way to reuse it.... Quote Link to comment Share on other sites More sharing options...
dsaba Posted April 23, 2007 Share Posted April 23, 2007 from my understand: 1. you store the max number in a database already 2. you use this data to create the file you want to read why can't you just query the database then and now you know what to look for in the file you're reading? Quote Link to comment Share on other sites More sharing options...
Guest prozente Posted April 23, 2007 Share Posted April 23, 2007 this should work <pre><?php $data = <<< eDATA <option value="13">African Nations Cup XXV</option> <option value="16">asd</option> <option value="7">Champions League</option> <option value="1">English Premiership</option> eDATA; preg_match_all('/<option value="([\d]+)">(?:.*)<\/option>/', $data, $matches); echo 'High value = '.max($matches[1])."\n"; ?></pre> 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.