PHP - Convert An Array Bytes To Mb Php
I have this php file which i use to get downloaded and uploaded data usage from my splynx radius server over API which outputs it as bytes making a very long string which i want to shorten into Mbps and from the arrays that i get from splynx server i would like help to convert the array "in_bytes" and "out_bytes" to MB. This is my whole code below. currently the output is in bytes and i need it to be in MB <?php $api_url = 'https://xxx/'; // Splynx URL $admin_login = "xxx"; // administrator login $admin_password = "xxx"; // administrator password $api = new SplynxAPI($api_url); $api->setVersion(SplynxApi::API_VERSION_2); $isAuthorized = $api->login([ 'auth_type' => SplynxApi::AUTH_TYPE_ADMIN, 'login' => $admin_login, 'password' => $admin_password, ]); if (!$isAuthorized) { exit("Authorization failed!\n"); } $customerApiUrl_online = "admin/customers/customers-online"; $customers_params = [ 'main_attributes' => [ 'status' => ['IN', ['active', 'blocked']] ]]; $result_online = $api->api_call_get($customerApiUrl_online); $customers_online = $api->response; ?> <table class="table table-transparent"> <thead> <tr> <th>DOWNOAD</th> <th>UPLOAD</th> </tr> </thead> <tbody> <?php foreach($customers_online as $item) :?> <tr> <td><?php echo $item['in_bytes']; ?></td> <td><?php echo $item['out_bytes']; ?></td> </tr> <?php endforeach;?> </tbody> </table>
Similar TutorialsThis topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=314962.0 I have this form:
<form method="get"> I wish to access the following chart by the number and the headings names. field text mysqlfield 1 username Please enter a username un 2 name Please enter you name nm 3 age Please enter your age ag 4 town What town do you live in tw 5 postcode What is your postcode pc I place the field and the text in to a form and use the mysqlfield to placce the data in the mysql database. what i do not know is how to store the array data and how to access it.
<?php $srs = array(); for ($section = 1; $section < 5; $section++) { for ($row = $section; $row < 10; $row++) { for ($seat = $row; $seat < 20; $seat++) { $srs[] = array( 'section_name' => $section, 'row_name' => $row, 'seat_name' => $seat); } } } output(convert_array($srs)); // Converts the array function convert_array($input) { return $input; } function output($obj) { echo "<pre>"; print_r($obj); echo "</pre>"; die; } ?>
I'm trying to convert those array number to string, add implode() to make it happen, but seem PHP didn't recognize variable in $input. Like this implode("Section: ", $input) or (Section: ", $srs). Can you help me? Thanks, Gary Edited October 16, 2019 by sigmahokiesHi everybody, I need some help about how to convert string to array name. I have the following function which pass $_REQUEST type as parameter. It is not working because I don't know how to convert $method to $_GET or $_POST in a proper way. Do anybody know how? Code: [Select] function validateIfFilled($method, $fields) { $exploded=explode(",",$fields); foreach($exploded as $field){ if(empty($method[trim($field)])){ return false; } } return true; }; if(!validateIfFilled('$_GET', "email, password, address")) ... Thank you! this is my solution:
$x = ['a' => 2, 'b' => 1, 'c' => 4, 'd' => 1]; $x1 = array_keys($x); $x2 = array_values($x); $z = []; for ($i=0; $i<count($x); $i++) { array_push($z, [$x1[$i],$x2[$i]] ); } print_r($z); //[['a', 2], ['b', 1], ['c', 4], ['d', 1]];is there easier (more elegant) way to do the same ? Hi guys! I need some help with a code problem. I've a form with 2 inputs, one single and one multiline, and I need to pass the value of both into an array, var1 (single input) is the same for every line and var2 (multiline) change with every line Hoe can i do it? How can i convert an array of results to a single comma separated string so that I can run it through an SQL query? Is there something like str_pad to make a string with a fixed width on the bases of bytes (not characters). If not, is it possible to safely convert characters to bytes to have a fixed width (of bytes). As a matter of fact, I want to use the strings (to be written to a file) as offsets for reading lines with fseek. Thanks This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=352847.0 Hello guys, I'm new in php and now I'm trying to make an php installer Right now it compress php project/dump database with gzip in a file called install.php and the idea is when the user run install.php in his browser he can choose directory, overwrite existing file etc... The problem is that when I try to run install.php in firefox I get this error: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 134217728 bytes) in Unknown on line 0 and when I run it with chrome I get this: <code> <?php //Compressed with Php Installer 0.5 //Directory list $directory = array(); $directory['C:\xampp\htdocs\magnatest'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/3dtags/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/__grundlayout/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/__grundlayout/bilder/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/actions/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/admin/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/admin/images/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/admin/images/customize/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/admin/jpgraph/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/admin/jpgraph/lang/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/attachments/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/attachments/process/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000002/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000007/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000015/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000019/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000026/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000028/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000029/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000030/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000031/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000034/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000035/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000062/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000064/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000065/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000068/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000070/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000072/'] = array( 'perms' => 16895 ); ................................................. .... ................................................. ............ ................................................. </code> Can anyone tell me what might be the problem ? Is it a memory size problem ? Hi again, I did a simple request and i get right response from curl_exec($ch); but when i call the static method str_get_html my result is always the same. QuoteFatal error: Allowed memory size of 536870912 bytes exhausted I tried increase the memory memory_limit=2048M but the result is the same. Proof of memory limit: Memory Limit I also tried ->clear(); unset(); but doesn't work. I'm using the following library: kub-at/php-simple-html-dom-parser My code: $url = "https://www.php.net"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, []); $this->callback = HtmlDomParser::str_get_html(curl_exec($ch)); .... Any tips? I can use regular expression, but will be my last choice. Thank you! I'm getting a fatal memory error and have been unable to figure out what is causing it. To make it worse, the allowed memory size does not appear to be related in any way to the memory_limit value. Here's the information: Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 128 bytes) in template.php on line 164 Excerpt from template.php (line 164 is where $max is assigned): ... else if(isDateType($type) || isTimestampType($type) || isDatetimeType($type)) { $min = htmlentities($countpost['constraints'][$tablename][$fieldname]['min'], ENT_QUOTES); $max = htmlentities($countpost['constraints'][$tablename][$fieldname]['max'], ENT_QUOTES); echo "\t\tFrom: <input name=\"constraints[$tablename][$fieldname][min]\"" ." type=text value=\"$min\" onclickXSSCleaned=\"toggleCalendar(this)\" readonly>\n"; echo "\t\tTo: <input name=\"constraints[$tablename][$fieldname][max]\"" ." type=text value=\"$max\" onclickXSSCleaned=\"toggleCalendar(this)\" readonly>\n"; } ... These two lines were included at the top of the script and printed "Base Memory Usage: 473172 Memory Limit: -1": echo "Base Memory Usage: ". memory_get_usage() ."\n"; echo "Memory Limit: ". ini_get('memory_limit') ."\n"; I also get the same error in a slightly different location: Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 1 bytes) in template.php on line 153 Excerpt from template.php (line 153 is the simple variable assignment of an empty string): ... if(!isset($countpost['constraints'][$tablename][$fieldname]['value'])) $countpost['constraints'][$tablename][$fieldname]['value'] = ""; ... If I refresh the page repeatedly, the error will predictably occur at the same place. Once I change any code (even slightly), the location of the error will change to a new location, sometimes into an included file. The size of "tried to allocate X bytes" also changes. The only constant in this whole mess is the allowed memory size (which is ALWAYS 262144, no matter what the actual memory limit is). I had previously set memory_limit to -1 in the php.ini file, which seems to have no effect on the error. I am not using a .htaccess file. Changing the memory_limit doesn't change the "allowed memory size" whether it's set to 16M, 64M or whatever. I've restarted apache after each change in php.ini. I have memory_get_usage in the code several times to watch the memory. There are small changes, and a change of about 300k when I first load another file. The max gets up to 1048576 bytes (memory_get_peak_usage). 1 Mb does not seem very large to me and is much smaller than the memory_limit. Also, today I wrote a short php script to just use up memory. This was just to test php and see if my installation is messed up. It worked just fine and I got up to 128Mb used without encountering the error above. So it's something in my code. This is using php 5.3.2, apache2 2.2.14, on Ubuntu 10.04. Any insights would be greatly appreciated. Rage. The whole error message reads: Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 16 bytes) Dunno bout you but that doesn't make sense to me! Anywho I am constantly getting this error when any PHP variables are stored or anything. I'm guessing thats the case coz its saying the error is on line 6 which is: $card = rand(1,52); I tried a search on google but just got confused, is there a simple explanation why this is happening? thanks alot guys Hi , As you may all have experienced this problem is there way we can non-healthy exit of script ..due to memory problem........??? I got to know..we avoid this......by properly managing our php memory by unset function. remove unusable variables and objects from memory...... Is there any way we can check each time inside the script -to check memory is available or sleep for some time and check again.......to proceed without exit........ Is there a way to catch this fatal error and take necessary steps to avoid exit........ Thanks, redfort :confused: I have a wordpress site that has this error in my error logs and seems to be causing the site to load very slow: PHP Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 64 bytes) in /home/name/public_html/wp-includes/meta.php on line 339 this is line 339: Code: [Select] $cache[$mpid][$mkey] = array(); a couple line above and below: Code: [Select] if ( !empty($meta_list) ) { foreach ( $meta_list as $metarow) { $mpid = intval($metarow[$column]); $mkey = $metarow['meta_key']; $mval = $metarow['meta_value']; // Force subkeys to be array type: if ( !isset($cache[$mpid]) || !is_array($cache[$mpid]) ) $cache[$mpid] = array(); if ( !isset($cache[$mpid][$mkey]) || !is_array($cache[$mpid][$mkey]) ) $cache[$mpid][$mkey] = array(); // Add a value to the current pid/key: $cache[$mpid][$mkey][] = $mval; } } Can some please help this is causing major issues. Hi. I tried to add some more if statements to check for validation and I'm now getting this error. The "on line ###" changes depending how many fields are FALSE. Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 35 bytes) in /home/content/f/u/s/fusionfashion/html/registration.php on line 133 I think it has to do with the php.ini file. So I added the memory_limit in the php.ini file. Code: [Select] register_globals = off allow_url_fopen = off expose_php = Off max_input_time = 60 variables_order = "EGPCS" extension_dir = ./ upload_tmp_dir = /tmp precision = 12 memory_limit = 128M post_max_size = 128M SMTP = relay-hosting.secureserver.net url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset=" [Zend] zend_extension=/usr/local/zo/ZendExtensionManager.so zend_extension=/usr/local/zo/4_3/ZendOptimizer.so But I'm still getting the error. How to I check my php version and this value within a browser? <?php phpinfo() ?> Found this. Its showing 64M in LOCAL and MASTER. But I just updated the local? Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 4864 bytes) in /home/a5418385/public_html/scripts/status.php on line 2 What does this mean? |