PHP code example of rmtram / jsonp-parser
1. Go to this page and download the library: Download rmtram/jsonp-parser 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/ */
rmtram / jsonp-parser example snippets
$parser = new Rmtram\JsonpParser\Jsonp();
$parser->encoder(['name' => 'example'])
->encode();
// default callbackName = callback
string(28) "callback({"name":"example"})"
$parser = new Rmtram\JsonpParser\Jsonp();
$parser->encoder(['name' => 'example'])
->callback('example')
->encode();
string(28) "example({"name":"example"})"
$parser = new Rmtram\JsonpParser\Jsonp();
$parser
->encoder([['name' => 'example']])
->depth(1)
->encode();
false
$parser = new Rmtram\JsonpParser\Jsonp();
$parser
->encoder([['name' => 'example']])
->option(JSON_UNESCAPED_UNICODE)
->encode();
$parser = new Rmtram\JsonpParser\Jsonp();
var_dump($parser->decoder('callback({"name": "example"})')->toArray());
array(1) {
["name"]=> string(7) "example"
}
$parser = new Rmtram\JsonpParser\Jsonp();
var_dump($parser->decoder('callback({"name": "example"})')->toObject());
object(stdClass)#45 (1) {
["name"]=> string(7) "example"
}
$parser = new Rmtram\JsonpParser\Jsonp();
$parser->decoder('callback(
{"name":"example"})'
)->trimEOL()->toArray();
array(1) {
["name"]=> string(7) "example"
}
$parser = new Rmtram\JsonpParser\Jsonp();
$parser->decoder('callback(
{"name":"example"})'
)->toArray();
null
$parser = new Rmtram\JsonpParser\Jsonp();
$parser
->decoder('callback([{"name": "example"}])')
->depth(1)
->toArray();
null
$parser = new Rmtram\JsonpParser\Jsonp();
$parser
->decoder('callback([{"name": "example"}])')
->option(JSON_BIGINT_AS_STRING)
->toArray();
$parser = new Rmtram\JsonpParser\Jsonp();
$parser->is('callback([1,2,3])');
true
$parser = new Rmtram\JsonpParser\Jsonp();
$parser->is('callback[1,2,3])');
false
$parser = new Rmtram\JsonpParser\Jsonp();
$parser->is('callback(
[1,2,3])', true);
true
$parser = new Rmtram\JsonpParser\Jsonp();
$parser->is('callback(
[1,2,3])', false);
false
$parser = new Rmtram\JsonpParser\Jsonp();
$parser->is('callback([1,2,3])(1,2,3)', false, false);
true
$parser = new Rmtram\JsonpParser\Jsonp();
$parser->is('callback([1,2,3])(1,2,3)', false, true);
false
$parser = new Rmtram\JsonpParser\Jsonp();
$parser->is('callback([1,2,3])(1,2,3', false, false);
false
$parser = new Rmtram\JsonpParser\Jsonp();
$parser->is('callback([1,2,3])(1,2,3', false, true);
false
$parser = new Rmtram\JsonpParser\Jsonp();
$parser->is('callback(example)', false, false);
true
$parser = new Rmtram\JsonpParser\Jsonp();
$parser->is('callback(example)', false, true);
false
//@param string $jsonp jsonp string.
//@param boolean $trimEOL (trim CR+LF/CR/LF)
//@param boolean $strict true => 'regex and json_decode', false => 'regexp'
is($jsonp, $trimEOL = false, $strict = true)