Calculator - PHP Online
Form of PHP Sandbox
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Calculator.php
- <?php
- function getOptions($type){
- $options = [
- 'Split-System' => [
- 'availableTypes' => ['Split System A/C Condensers'],
- 'mainBtu' => 'cbtu',
- ],
- 'Ductless Mini-Split' => [
- 'availableTypes' => ['Mini-Split'],
- 'mainBtu' => 'cbtu',
- ],
- 'Self-Contained Package' => [
- 'availableTypes' => ['Gas Furnace', 'Package Gas', 'Package Heat Pump', 'Packaged A/C'],
- 'mainBtu' => 'cbtu',
- ],
- 'Geothermal' => [
- 'availableTypes' => ['Split System Heat Pump', 'Modular Blower', 'Evaporator Coils'],
- 'mainBtu' => 'cbtu',
- ],
- ];
- return $options[$type];
- }
- function getBtuForSqft(){
- return [
- 'cbtu' => [
- 'basic' => [
- '1' => 25,
- '2' => 24,
- '3' => 24,
- '4' => 22.5,
- '5' => 20,
- '6' => 19,
- '7' => 18,
- ],
- 'above' => [
- '1' => 18,
- '2' => 17,
- '3' => 16,
- '4' => 15,
- '5' => 13.25,
- '6' => 12.5,
- '7' => 12,
- ],
- 'outstanding' => [
- '1' => 14.15,
- '2' => 14.15,
- '3' => 14.15,
- '4' => 13.275,
- '5' => 11.8,
- '6' => 11.21,
- '7' => 10.62,
- ],
- ],
- 'hbtu' => [
- 'basic' => [
- '1' => 0,
- '2' => 30,
- '3' => 35,
- '4' => 40,
- '5' => 45,
- '6' => 50,
- '7' => 55,
- ],
- 'above' => [
- '1' => 0,
- '2' => 22.6,
- '3' => 25.2,
- '4' => 28.8,
- '5' => 32.4,
- '6' => 36,
- '7' => 39.6,
- ],
- 'outstanding' => [
- '1' => 0,
- '2' => 17,
- '3' => 20,
- '4' => 23,
- '5' => 25.5,
- '6' => 28.3,
- '7' => 31.15,
- ],
- ]
- ];
- }
- function getClimateZoneApi($zipCode)
- {
- $json = file_get_contents('http://www.afanalytics.com/api/climatezone/' . $zipCode);
- if($json) {
- $data = json_decode($json);
- return $data->climate_zone_number;
- }
- return null;
- }
- //Sort an array of xml objects
- function xsort(&$nodes, $child_name, $order = SORT_ASC)
- {
- $sort_proxy = array();
- foreach ($nodes as $k => $node)
- {
- $sort_proxy[$k] = (string) $node->$child_name;
- }
- array_multisort($sort_proxy, $order, $nodes);
- }
- function getProducts($type, $btuArray){
- $options = getOptions($type);
- $types = $options['availableTypes'];
- $btu_type = $options['mainBtu'];
- $btu = $btuArray[$btu_type];
- $result = [];
- $temp = [];
- $productsXml = simplexml_load_file('https://mrcool.com/feeds/sysselect/sysselect.xml');
- if ($productsXml == null) {
- echo(json_encode($result));
- wp_die();
- }
- foreach ($productsXml->product as $product) {
- if (in_array($product->type, $types) && $btu) {
- $productBtu = (int)$product->$btu_type;
- getBtuRange($temp, $productBtu, $btuArray[$btu_type]);
- }
- }
- correctBtuRange($temp, $btuArray[$btu_type]);
- $types[] = 'Air Handler';
- foreach ($productsXml->product as $product) {
- $productBtuArray = explode("-", $product->$btu_type);
- if (in_array($product->type, $types) && $btu) {
- //Finding exact matches
- if (count($productBtuArray) == 1) {
- if($productBtuArray[0] >= $temp['minBtu'] && $productBtuArray[0] <= $temp['maxBtu']) {
- $result[] = $product;
- }
- }else{
- if($productBtuArray[0] >= $temp['minBtu'] && $productBtuArray[1] <= $temp['maxBtu']){
- $result[] = $product;
- }
- }
- }
- }
- if($btu_type != 'hbtu'){
- check_hbtu($result, $btuArray['hbtu']);
- }
- xsort($result, $btu_type, SORT_ASC);
- return $result;
- }
- function check_hbtu(&$result, $hbtu){
- foreach ($result as $product){
- if($product->hbtu < $hbtu){
- $product->error = 'You will might require additional source of heating';
- }
- }
- }
- //Search 4 products with maximum match.
- function getBtuRange(&$temp, $productBtu, $btu){
- if($btu && $productBtu){
- if(empty($temp['minBtu']) && $productBtu < $btu) {
- $temp['minBtu'] = $productBtu;
- }elseif($productBtu > $temp['minBtu'] && $productBtu < $btu){
- $temp['minBtu'] = $productBtu;
- }
- if(empty($temp['maxBtu']) && $productBtu > $btu) {
- $temp['maxBtu'] = $productBtu;
- }elseif($productBtu < $temp['maxBtu'] && $productBtu > $btu){
- $temp['maxBtu'] = $productBtu;
- }
- }
- }
- function correctBtuRange(&$temp, $btu){
- if(!isset($temp['minBtu'])) $temp['minBtu'] = $btu;
- if(!isset($temp['maxBtu'])) $temp['maxBtu'] = $btu;
- }
- function getAddress($zipCode)
- {
- $json = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address=' . $zipCode . '&sensor=true&key=AIzaSyDCtjwqtJRcsplfP1wfZ9RfH2fVOYU3cCc');
- if($json) {
- $data = json_decode($json);
- return $data->results[0]->formatted_address;
- }
- return null;
- }
- function get_ingram_url_callback()
- {
- $result['status'] = 'error';
- $result['url'] = '';
- $result['message'] = '';
- if (isset($_POST['data']) && ! empty($_POST['data'])) {
- $params = [];
- parse_str($_POST['data'], $params);
- $climateZone = getClimateZoneApi($params['zipCode']);
- $type = $params['type'];
- $insulation = $params['insulationValue'];
- $sqft = $params['square'];
- $btuArray = [];
- $BtuArray = getBtuForSqft();
- foreach ($BtuArray as $key => $btu){
- $btuArray[$key] = $btu[$insulation][$climateZone] * $sqft;
- $result['message'] .= "$key - $btuArray[$key], ";
- }
- $result['status'] = 'ok';
- $result['message'] .= "climate-zone - $climateZone. Address - " . getAddress($params['zipCode']);
- $result['products'] = getProducts($type, $btuArray);
- }
- echo(json_encode($result));
- wp_die();
- }
- ?>