PHP code example of jdkysq / translator

1. Go to this page and download the library: Download jdkysq/translator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jdkysq / translator example snippets


/**
 * 数据转换
 * @param string $from 来源格式
 * @return From
 */
public function from(string $from): From

/**
 * 支持的格式检查
 * @param string $format 探测目标格式
 * @return bool
 */
public static function hasFormat($format): bool

/**
 * 转化的目标格式
 * @param string $to
 * @return mixed
 */
public function to(string $to)

/**
 * @return mixed
 */
public function encode()
/**
 * @return array
 */
public function decode() :array

$json = '{"id":"1682333591565606218","wfr":"spider","for":"pc"}';
$translator = new \jdkysq\Translator\Msg($json);
$ret = $translator->from('json')->to('xml');
/**
 * <?xml version="1.0" encoding="UTF-8"

$json = '{"id":"1682333591565606218","wfr":"spider","for":"pc"}';
$translator = new \jdkysq\Translator\Translator();
$ret = $translator->to('json','xml',$json);
/**
 * <?xml version="1.0" encoding="UTF-8"

$translator = new \jdkysq\Translator\Translator();
$ret = $translator->isFormat('xml');
var_dump($ret); //true