Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php到C#转换器_C#_Php - Fatal编程技术网

php到C#转换器

php到C#转换器,c#,php,C#,Php,我需要将此PHP代码转换为C#。有没有一个工具或网站可以让这成为可能 public function call($method, array $params) { // Add the format parameter, only 'json' is supported at the moment if (!array_key_exists('format', $params)) { $params['format'] = 'json'; } $

我需要将此PHP代码转换为C#。有没有一个工具或网站可以让这成为可能

public function call($method, array $params) {
    // Add the format parameter, only 'json' is supported at the moment
    if (!array_key_exists('format', $params)) {
        $params['format'] = 'json';
    }

    $url = "{$this->_url}/{$method}";
    $ch = $this->_getCurlHandle($url);

    if (!$ch) {
        throw new Fuze_Client_Exception("Unable to create a cURL handle");
    }

    // Set the request parameters
    $queryString = http_build_query($params);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $queryString);

    // Fire!
    $result = $this->_executeCurl($ch);

    // All API response payloads should be valid json with 'code' and
    // 'message' members
    $json = json_decode($result);
    if ( !($json instanceof stdClass)
            || !isset($json->code)
            || !isset($json->message) ) {

        throw new Fuze_Client_ServerException(
            "Invalid JSON payload received", $result, $info['http_code']);
    }

    if ( $json->code >= 500 && $json->code < 600) {
        throw new Fuze_Client_FaultException($json);
    }

    return $json;
}
公共函数调用($method,array$params){
//添加format参数,目前只支持“json”
如果(!array_key_存在('format',$params)){
$params['format']='json';
}
$url=“{$this->url}/{$method}”;
$ch=$this->\u getCurlHandle($url);
如果(!$ch){
抛出新的Fuze_客户端_异常(“无法创建卷曲句柄”);
}
//设置请求参数
$queryString=http\u build\u query($params);
curl_setopt($ch,CURLOPT_POSTFIELDS,$queryString);
//开火!
$result=$this->\u executeCurl($ch);
//所有API响应有效负载都应该是带有“code”和
//“消息”成员
$json=json_decode($result);
if(!($json instanceof stdClass)
||!isset($json->code)
||!isset($json->message)){
抛出新Fuze\u客户端\u服务器异常(
“接收到无效的JSON有效负载”、$result、$info['http_code']);
}
如果($json->code>=500&&$json->code<600){
抛出新的Fuze\u客户端\u FaultException($json);
}
返回$json;
}

我不知道有什么工具可以从PHP转换成C。如果有这样的事情,我不会相信它能正确地进行转换。因此,您可以选择:

  • 学习C#
  • 把它传给能转换它的人
    • 这可能会有所帮助。 它有一个转换引擎,但事实上它得到了“白皮书”的支持 这让我相信,前面还有很艰难的路要走


      也许你应该看看。它不是一个转换器,但它允许您为.Net编译PHP代码——因此您应该能够从C#调用PHP方法。
      这是一个开源项目,源代码是托管的

      没有转换器,但您可以看看。它是一种多平台的开源语言,可以编译成其他语言,包括C#。语法类似于PHP


      无论如何,对于这个代码段,手动转换是最好的方法。

      您可以使用SWI Prolog的
      transpiler
      库将一小部分PHP自动转换为C。这是一个使用此库的简短程序:

      $sql = "SELECT num.name,num.on from table WHERE on = '0'";
      
      $query = mysql_query($sql);
      
      $arr =mysql_fetch_array($query);
      
      $s = array($arr['name']);
      
      if(in_array('1',$s)){echo "yes";}else{echo "no";} 
      
      :- use_module(library(transpiler)).
      :- set_prolog_flag(double_quotes,chars).
      :- initialization(main).
      
      main :- 
          Input = "function add($a,$b){return $a.$b;}function squared($a){return $a*$a;}function add_exclamation_point($parameter){return $parameter.\"!\";}",
          translate(Input,'php','c#',X),
          atom_chars(Y,X),
          writeln(Y).
      
      这是程序的C#输出:

      使用我们正在开发的PHP编译器,使PHP项目成为常规的.NET项目(如F#或C++/CLI),而不是转换(这将导致无法管理的意大利面代码):

      通过这种方式,除其他事项外,您可以保持PHP代码的可维护性,同时可以从C#无缝地使用它

      一些资源:


      这似乎是更大问题的一部分。你到底需要翻译它的哪些方面?卷曲部分相关:可能不是你要找的,但是PHP的脸谱HIPPHP将PHP转换成C++。(是的,我知道你要的是C,但这是我能想到的最接近的东西:D)。并不会真正为您提供任何转换后的代码,但会提高您的性能,若这正是您所追求的。。。旧的学校手册“手工”转换应该是最简单和最快的方式,我认为。。。对于一些kloc,考虑使用phalanger(正如我在下面已经提到的)。如果这不起作用,请尝试使用互操作而不是转换(例如,通过服务桥接调用)。检查此站点。。。它的工作。。。你只需要更改一部分类和名称+1,附议。将源代码从一种语言转换为另一种语言是一项复杂的任务,我怀疑是否有一种工具能够使之成为可能,更不用说可靠性了:)。与其进行转换,不如将现有的PHP代码集成到.NET中,例如使用正在开发的Phalangerused@JakubM然后对其进行逆向工程。事实上,转换简单的代码块一定不会太难,只是没有人认为它值得去解决。请注意,“转换源代码”被称为“编译”。这没什么问题。您可以编译F#、C++/CLI、TypeScript并直接从C使用它。为什么不编译PHP?使用上面提到的或与问题无关的Phalanger,或者主题Phalanger已被拒绝,请使用。
      public static string add(string a,string b){
              return a+b;
      }
      public static int squared(int a){
              return a*a;
      }
      public static string add_exclamation_point(string parameter){
              return parameter+"!";
      }