Pass through options and depth.

This commit is contained in:
Dave Longley 2014-03-20 14:03:22 -04:00
parent c6f06ab52a
commit f1244cefa9
1 changed files with 7 additions and 4 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* PHP implementation of the JSON-LD API. * PHP implementation of the JSON-LD API.
* Version: 0.3.0 * Version: 0.3.1
* *
* @author Dave Longley * @author Dave Longley
* *
@ -166,16 +166,19 @@ function jsonld_to_rdf($input, $options=array()) {
* *
* @param mixed $input the native PHP stdClass or array which will be * @param mixed $input the native PHP stdClass or array which will be
* converted to JSON by json_encode(). * converted to JSON by json_encode().
* @param int $options the options to use.
* [JSON_PRETTY_PRINT] pretty print.
* @param int $depth the maximum depth to use.
* *
* @return the encoded JSON data. * @return the encoded JSON data.
*/ */
function jsonld_encode($input) { function jsonld_encode($input, $options=0, $depth=512) {
// newer PHP has a flag to avoid escaped '/' // newer PHP has a flag to avoid escaped '/'
if(defined('JSON_UNESCAPED_SLASHES')) { if(defined('JSON_UNESCAPED_SLASHES')) {
return json_encode($input, JSON_UNESCAPED_SLASHES); return json_encode($input, JSON_UNESCAPED_SLASHES | $options, $depth);
} }
// use a simple string replacement of '\/' to '/'. // use a simple string replacement of '\/' to '/'.
return str_replace('\\/', '/', json_encode($input)); return str_replace('\\/', '/', json_encode($input, $options, $depth));
} }
/** /**