Skip to content

Instantly share code, notes, and snippets.

@ramonfincken
Created December 31, 2023 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramonfincken/d416572d2580fb7ae803dfbdfeef5b86 to your computer and use it in GitHub Desktop.
Save ramonfincken/d416572d2580fb7ae803dfbdfeef5b86 to your computer and use it in GitHub Desktop.
Read i3d status page
<?php
$url = 'https://status.i3d.net/';
function get_page_as_string( $url ) {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_VERBOSE, 0 );
curl_setopt( $ch, CURLOPT_HEADER, 0 );
return curl_exec( $ch );
}
$regex_maintenance = '~section-scheduled.+?section-timeline~sm';
$regex_maintenance_items = '~id=".+?([0-9]+?)".+?<strong>(.+?)<\/strong>.+?href="(.+?)"~s';
$the_page_as_string = get_page_as_string( $url );
preg_match_all( $regex_maintenance, $the_page_as_string, $matches );
if ( isset( $matches[0][0] ) ) {
$maintenance = $matches[0][0];
preg_match_all( $regex_maintenance_items, $maintenance, $matches );
if( isset( $matches[2][0] ) ) {
$count = count( $matches[2] );
$i = 0;
while( $i+1 < $count ) {
$item_title = $matches[2][$i];
$item_url = $matches[3][$i];
if( str_starts_with( $item_url, '#' ) ) { $item_url = $url.$item_url; }
$i++;
echo $item_title.$item_url;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment