954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Is This Possible? $filename fopen Question

What I an wanting to do here is have the script email me when the user count reaches X number of listeners on my RR Scanner Feed.
Is This Possible?

<?php
    $filename = '<script language="JavaScript" src="http://api.radioreference.com/audio/listeners.php?feedId=10734"></script>'; 
    $fp = fopen( $filename,"r"); 
    if ($filename >= X) {
  //// ($email Me @ My Email Address Or Any Address I Add Here) ////
  exit();
}                       
    fclose( $fp ); 
    print "Online=$filename";   
?>
wxflint
Newbie Poster
17 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

You'd have to store the file open count somewhere (file/database), but you would need a decrement too when sombody stops using it.

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 
You'd have to store the file open count somewhere (file/database), but you would need a decrement too when sombody stops using it.

Thanks I see what you are saying I have found this code here but for the life of me I cant figure out how to get it to read the above mentioned

$filename = '<script language="JavaScript" src="http://api.radioreference.com/audio/listeners.php?feedId=10734"></script>';


and get it to write to a txt file.

<?php
    $filename = "PHPCounter.txt"; 
    $fp = fopen( $filename,"r");             
    $Old = fread($fp, 100);
    fclose( $fp );
    $Old = split ("=", $Old, 5);        
    $NewCount = $Old[1] + '1';        
    $New = "Online=$NewCount";        
    $fp = fopen( $filename,"w+");         
    if (flock($fp, 2)) { 
      fwrite($fp, $New, 100);
    }         
    fclose( $fp );

    print "Online=$NewCount";     
?>
wxflint
Newbie Poster
17 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

What do you want with that script tag ?

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 
What do you want with that script tag ?

What I am wanting is have the script email me when the user count reaches X number of listeners on my RR Scanner Feed.
So it would read the file

$filename = '<script language="JavaScript" src="http://api.radioreference.com/audio/listeners.php?feedId=10734"></script>';


and write it to a txt file and then email me when the listener count reaches X number if listeners.

wxflint
Newbie Poster
17 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

That script is hosted by another party, and you want to read the number it returns in the document.write ? And based on that number send an email ?

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 
That script is hosted by another party, and you want to read the number it returns in the document.write ? And based on that number send an email ?

pritaeas, Yes sir that is correct.

wxflint
Newbie Poster
17 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

I think this should do it (can't test right now):

$filename = "http://api.radioreference.com/audio/listeners.php?feedId=10734";
$data = file_get_contents($filename);
preg_match('/document\.write\(\'(.*?)\'\);/i', $data, $result)
$listeners = $result[1];
echo $listeners;
pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

I think this should do it (can't test right now):

$filename = "http://api.radioreference.com/audio/listeners.php?feedId=10734";
$data = file_get_contents($filename);
preg_match('/document\.write\(\'(.*?)\'\);/i', $data, $result)
$listeners = $result[1];
echo $listeners;

Thank you so much. That was it and works great its nice to come on here and always get the help needed. its people like you that make Daniweb what it is today, Thanks again for the help..

wxflint
Newbie Poster
17 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You