Jump to content

retrieving specific file info...


mkosmosports

Recommended Posts

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!

Link to comment
Share on other sites

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.'">'

Link to comment
Share on other sites

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....

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Guest prozente

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>

 

Link to comment
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.