function get_usage($url) { global $limit; global $monthly_limit; global $bandwidth_used; global $bandwidth_remaining; global $bandwidth_remaining_percentage; $usage_stats = @file_get_contents($url); if ($usage_stats === "false") { get_usage($url); } else { $limit = $limit * 1000000000.0; $total = get_string_between($usage_stats, "<total>", "</total>"); $total = floatval(get_string_between($total, "<download>", "</download>")); $used = get_string_between($usage_stats, "<used>", "</used>"); $used = floatval(get_string_between($used, "<download>", "</download>")); $free = get_string_between($usage_stats, "<grace>", "</grace>"); $free = floatval(get_string_between($free, "<download>", "</download>")); $monthly_limit = number_format($limit / 1000000000, 2); //. " GB"; $bandwidth_used = number_format($used / 1000000000, 2); //. " GB"; $bandwidth_remaining = number_format(($limit - $used) / 1000000000, 2); //. " GB"; $bandwidth_remaining_percentage = number_format($used * 100.0 / $limit, 1); } }
function pleac_Doing_Something_with_Every_Element_in_a_List() { foreach ($list as $item) { // do something with $item } // Environment listing example // PHP defines a superglobal $_ENV to provide access to environment // variables. // Beware, array assignment means copying in PHP. You need to use // the reference operator to avoid copying. But we want a copy here. $env = $_ENV; // PHP can sort an array by key, so you don't need to get keys, // and then sort. ksort($env); foreach ($env as $key => $value) { echo "{$key}={$value}\n"; } // Literal translation of Perl example would be: $keys = array_keys($_ENV); sort($keys); foreach ($keys as $key) { echo "{$key}={$_ENV[$key]}\n"; } // This assumes that MAX_QUOTA is a named constant. foreach ($all_users as $user) { $disk_space = get_usage($user); if ($disk_space > MAX_QUOTA) { complain($user); } } // You can't modify array's elements in-place. $array = array(1, 2, 3); $newarray = array(); foreach ($array as $item) { $newarray[] = $item - 1; } print_r($newarray); // Before PHP 5, that is. You can precede the reference operator // before $item to get reference instead of copy. $array = array(1, 2, 3); foreach ($array as &$item) { $item--; } print_r($array); // TODO: explain the old each() and list() iteration construct. // foreach is new in PHP 4, and there are subtle differences. }
<span class="drill-jlpt"> <?php echo round($use * 50 / $qq, 2); ?> </span> </td> </tr> <!--****************************************************--> <!--*************** について **************************--> <!--****************************************************--> <!--<tr> <? $use = get_usage('について','Intermediate','clickchoice'); $class = 'について'; $diff = 'Intermediate'; $q = '20'; $use = get_usage($class,$diff,'clickchoice'); $qq = count_Available_Clickchoice_Questions($class,$diff); $rq = ''; ?> <td class="text-center"> <a href="http://www.jpdrills.com/grammar-practice/clickchoice.php?class=について&diff=Intermediate&q=5" title="について Japanese Grammar Practice" itemprop="url"> <button type="button" class="btn btn-link btn-block btn-drill"> <b><span itemprop="about"><span itemprop="name">について</span></span></b> </button> </a> </td> <td class="small text-center" data-value="4"> <span itemprop="audience" itemscope itemtype="http://schema.org/EducationalAudience"> <abbr title="After Minna no Nihongo" itemprop="audienceType" > <span class="drill-jlpt">N2</span> </abbr>
</p></form> <p id="system_configuration_message_p"></p> <hr class="blue_hr thick_hr"> <?php } ?> <h3>Your usage</h3> <p class="smalltext_p">If you have used without making a reservation first, please click the button below. It can't be undone.</p> <div id="usage_div"><?php echo get_usage(); ?> </div> <p><input type="button" class="blue_button small_button" id="add_one_reservation_button" value="Add 1 to my reservations"></p> <p id="usage_message_p"></p> <hr> <?php if (global_reservation_reminders == '1') { ?> <h3>Your settings</h3>
?> <nav> <a href="call-usage.php?action=today">Today</a> <a href="call-usage.php?action=lm">Last Month</a> <a href="call-usage.php?action=all">All Calls</a> <span>Custom Report:</span> <form action="" method="GET"> <input type="hidden" name="action" value="custom" /> <input type="date" name="startd" placeholder="Start Date" /> <input type="date" name="endd" placeholder="End Date" /> <button type="submit">Generate</button> </form> </nav> <hr /> <?php $results = get_usage($action); if (count($results > 0)) { # echo '<pre>'.print_r($results,true).'</pre>'; ?> <table width=100%> <thead> <tr> <th>Category</th> <th>Description</th> <th>SID</th> <th>Start Date</th> <th>End Date</th> <th>Usage</th> <th>Usage Unit</th> <th>Price</th> <th>Price Unit</th>
</p></form> <p id="system_configuration_message_p"></p> <hr class="blue_hr thick_hr"> <?php } ?> <h3>Your usage</h3> <p class="smalltext_p">If you have used without making a reservation first, please click the button below. It can't be undone.</p> <div id="usage_div"><?php echo get_usage($conn); ?> </div> <p><input type="button" class="blue_button small_button" id="add_one_reservation_button" value="Add 1 to my reservations"></p> <p id="usage_message_p"></p> <hr> <?php if (global_reservation_reminders == '1') { ?> <h3>Your settings</h3>
<td class="small text-center text-muted drill-jlpt" style="font-size:0.8em" data-value="<?php echo $use; ?> "> <span class="drill-jlpt"> <?php echo $use; ?> </span> </td> </tr> <!--****************************************************--> <!--*************** について **************************--> <!--****************************************************--> <!--<tr> <? $use = get_usage('について','Intermediate','clickchoice');?> <td class="text-center"> <a href="http://www.jpdrills.com/grammar-practice/clickchoice.php?class=について&diff=Intermediate&q=5" title="について Japanese Grammar Practice" itemprop="url"> <button type="button" class="btn btn-link btn-block btn-drill"> <b><span itemprop="about"><span itemprop="name">について</span></span></b> </button> </a> </td> <td class="small text-center" data-value="4"> <span itemprop="audience" itemscope itemtype="http://schema.org/EducationalAudience"> <abbr title="After Minna no Nihongo" itemprop="audienceType" > <span class="drill-jlpt">N2</span> </abbr> </span> </td> <td class="small text-center text-muted drill-jlpt" style="font-size:0.8em" data-value="<?php