Php 辐射电平转换器

Php 辐射电平转换器,php,units-of-measurement,Php,Units Of Measurement,我正在做一些事情,我希望能够有一个像这样的网站转换器:不幸的是,没有这种转换器的来源,我在这方面的需要 谁能给我指出正确的方向,或者提供这个辐射单元转换器的源代码 一旦我找到了一个正确的答案,我愿意给一个正确和完美的来源350点赏金(当几天过去了,我可以设置赏金) 多谢各位 编辑: 从现在开始悬赏。我需要用PHP编写这个脚本,这样可以通过选择将输入的值转换为另一个辐射单元。看起来它主要是javascript。您可以在页面上查看源代码,查看他们为您的站点使用和解释的代码。管理多种格式之间的转换的最

我正在做一些事情,我希望能够有一个像这样的网站转换器:不幸的是,没有这种转换器的来源,我在这方面的需要

谁能给我指出正确的方向,或者提供这个辐射单元转换器的源代码

一旦我找到了一个正确的答案,我愿意给一个正确和完美的来源350点赏金(当几天过去了,我可以设置赏金)

多谢各位

编辑:


从现在开始悬赏。我需要用PHP编写这个脚本,这样可以通过选择将输入的值转换为另一个辐射单元。

看起来它主要是javascript。您可以在页面上查看源代码,查看他们为您的站点使用和解释的代码。

管理多种格式之间的转换的最简单方法就是维护一种类型的转换表,然后进行两部分转换以获得所需的格式。这样做会损失一定的精度,但是你确实应该有足够的精度来满足这样的需求(你总是可以通过在伦琴类型中添加更多的数字来提高精度)

有很多方法可以做到这一点,但我创建了一个
RadiationConverter
类来保持一切整洁,我做了一些链接来保持整洁。不过你明白了

<?php

class RadiationConverter {

 // these are the keys we'll reference when sending a type to the methods, 
 // along with a value for what we'll display each type as:
 private $conversion_display = array ( 
     'sievert' => 'sievert',
     'millisievert' =>  'millisievert',
     'microsievert' => 'microsievert',
     'j/kg'=> 'joule/kilogram', 
     'm2/s2' => 'square meter/square second',   
     'rem' => 'Roentgen eq. man',   
     'millirem' => 'millirem',  
     'imillicurie' => 'intensity millicurie',   
     'electrons'=> 'gray (Wr=1, X-ray, gamma ray, electrons)',  
     'alpha' => 'gray (Wr=20, alpha particles)',
     'roentgen'=> 'Roentgen/hour (numerical equivalent)');

 // this is a conversion table for sieverts to anything else
 // (note the conversion factor of 1 for sievert)
 private $conversion_table = array (
    'sievert'   =>  1,
    'millisievert'  =>  0.001,
    'microsievert'  =>  0.000001,
    'j/kg'  =>  1,  
    'm2/s2' =>  1,  
    'rem'   =>  0.01,   
    'millirem'  =>  0.00001,    
    'imillicurie'   =>  1,  
    'electrons' =>  1,  
    'alpha' =>  20,
    'roentgen'  =>  0.119331742243,
);

 private $type;
 private $amount;
 private $base_type; // this is what our conversion table is based on

 public function __construct($from_type='sievert', $amount = 0) {

   $from_type = strtolower($from_type);
   if(!array_key_exists($from_type,$this->conversion_display)) {
      throw new Exception ("Radiation type does not exist.");
   }
   $this->type = $from_type;
   $this->amount = $amount;
   $this->base_type = 'sievert'; // for reference only, really

 }

 public function amount($amount=null) {
  if(empty($amount)) return $this->amount;
  $this->amount = $amount;
  return $this;
 }

 public function types() {
    return $this->conversion_display;
 }

 public function display_name($type=null) {
    if (empty($type)) $type=$this->type;
    return $this->conversion_display[$type];
 }

 public function display_as($type){
   return $this->convert_to($type) . ' '.$this->display_name($type);
 }

 public function convert_to($type) {
  $type = strtolower($type);
  if(!array_key_exists($type,$this->conversion_display)) {
      throw new Exception ("Radiation conversion type does not exist.");
  }
  // first we convert to our base type, then convert that to the new type:
  return ($this->amount*$this->conversion_table[$this->type])/$this->conversion_table[$type];
 }

 public function base_type(){
    return $this->base_type;
 }


}
如果要在该站点上创建类似的表:

$display_amount = $_POST['amount'] . " " . $converter->display_name();

// just take the convert_from variable and cycle through all the types:
foreach($converter->types() as $type => $display) {
  echo  "$display_amount = " . $converter->display_as($type) . "<br />";
}
$display\u amount=$\u POST['amount']。" " . $转换器->显示_名称();
//只需从变量中获取convert_,并循环所有类型:
foreach($converter->types()作为$type=>$display){
echo“$display_amount=”.$converter->display_as($type)。“
”; }
为什么不尝试自己创建它?如果它的数学问题是困扰你的,那么这可能不是你的问题的正确位置。嗯,转换列在那里的页面上。我知道转换在那里,但我无法创建它。我对单位转换从来都不太在行,这是不对的。如果您实际查看源代码,您可以看到表单提交是通过JS处理的,但随后它会发布到PHP页面进行实际转换。很高兴提供帮助——我使用了类似的货币转换概念,尽管我是用Ruby编写的。
$display_amount = $_POST['amount'] . " " . $converter->display_name();

// just take the convert_from variable and cycle through all the types:
foreach($converter->types() as $type => $display) {
  echo  "$display_amount = " . $converter->display_as($type) . "<br />";
}