本文整理汇总了PHP中isJson函数的典型用法代码示例。如果您正苦于以下问题:PHP isJson函数的具体用法?PHP isJson怎么用?PHP isJson使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isJson函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: SaveMainMenu
function SaveMainMenu()
{
if (isset($_POST["action"])) {
switch ($_POST["action"]) {
case "save":
$json = rawurldecode($_POST["json"]);
$json = $content = stripslashes(str_replace("\\n", "\n", $json));
if (isJson($json)) {
if (file_put_contents("../core/menu-structure.json", $json) !== false) {
header('Content-Type: text/plain; charset=utf-8');
echo "success";
} else {
header('Content-Type: text/plain; charset=utf-8');
echo "failed";
}
} else {
header('Content-Type: text/plain; charset=utf-8');
echo "failed";
}
break;
case "reload":
header('Content-Type: text/plain; charset=utf-8');
$json_stream = file_get_contents("../core/menu-structure.json");
echo $json_stream;
break;
}
}
}
示例2: getHours
function getHours($hours, $format = true)
{
global $d;
$operation_hours = $hours;
if (isJson($operation_hours)) {
$hrs = json_decode($operation_hours, true);
} else {
$hrs = $operation_hours;
}
$h = '';
if (count($hrs) > 0 && is_array($hrs)) {
foreach ($d as $i => $v) {
foreach ($hrs as $index => $val) {
if ($v == $index) {
$index = ucwords($index);
if ($val['status'] == 'Opened') {
$t = explode(' ', $val['open']);
if ($t[1] == '1') {
$val['open'] = $t[0] . " AM ";
} else {
$val['open'] = $t[0] . " PM ";
}
$t = explode(' ', $val['close']);
if ($t[1] == '1') {
$val['close'] = $t[0] . " AM ";
} else {
$val['close'] = $t[0] . " PM ";
}
$hrs[$index] = $val['open'] . '-' . $val['close'];
} else {
$hrs[$index] = 'Closed';
}
}
}
}
$time = array_unique(array_values($hrs));
$hours = array();
foreach ($time as $i => $j) {
foreach ($hrs as $k => $l) {
if ($j == $l) {
$hours[$j][] = $k;
}
}
$hours[$j] = implode(', ', $hours[$j]);
}
if ($format) {
foreach ($hours as $m => $n) {
$h .= $n . ' ' . $m;
}
$h = ucwords($h);
} else {
$h = $hours;
}
return $h;
} else {
$h = $h = ucwords($operation_hours);
return $h;
}
}
示例3: JsonToArray
public function JsonToArray($json)
{
if (isJson($json)) {
$array = json_decode($json, true);
return $array;
} else {
throw exception("Invalid Json Array");
}
}
示例4: rendejson
function rendejson($array)
{
foreach ($array as $key => $value) {
if (isJson($value)) {
$array->{$key} = json_decode($value);
}
}
return $array;
}
示例5: SaveConfigStandard
function SaveConfigStandard($config_json)
{
$config_json = rawurldecode($config_json);
$config_json = stripslashes(str_replace("\\n", "\n", $config_json));
if (isJson($config_json)) {
if (file_put_contents("../config.json", $config_json) === false) {
echo "failed";
}
} else {
echo "failed";
}
}
示例6: getSplitHBooking
public function getSplitHBooking($post)
{
if (!isset($post['HBooking']) and isset($post['DocID'])) {
$bookingid = $post['DocID'];
} else {
if (isset($post['HBooking'])) {
$bookingid = $post['HBooking'];
} else {
$bookingid = '';
}
}
$a_post = array_map('base64_decode', explode('#|#', $bookingid));
$_return = array();
foreach ($a_post as $item) {
$_return[] = $post + isJson($item, true);
}
return $_return;
}
示例7: preparePage
function preparePage($id = false)
{
global $post, $ioa_meta_data, $super_options;
if (is_home()) {
return;
}
$ioa_options = array();
$ioa_meta_data['subtitle'] = '';
if (isset($post)) {
$ioa_meta_data['rad_data'] = get_post_meta($post->ID, "rad_data", true);
if (get_post_meta($post->ID, 'rad_version', true) == "" && !is_array($ioa_meta_data['rad_data'])) {
if (isJson($ioa_meta_data['rad_data'])) {
$ioa_meta_data['rad_data'] = json_decode(stripslashes($ioa_meta_data['rad_data']), true);
} else {
$ioa_meta_data['rad_data'] = base64_decode($ioa_meta_data['rad_data']);
$ioa_meta_data['rad_data'] = json_decode(stripslashes($ioa_meta_data['rad_data']), true);
}
}
$ioa_meta_data['title'] = get_the_title();
if (get_post_meta(get_the_ID(), '_post_subtitle', true) != "" && get_post_meta(get_the_ID(), '_post_subtitle', true) != "none") {
$ioa_meta_data['subtitle'] = get_post_meta(get_the_ID(), '_post_subtitle', true);
}
$ioa_options = get_post_meta(get_the_ID(), 'ioa_options', true);
}
if (!$id) {
$ioa_options = get_post_meta(get_the_ID(), 'ioa_options', true);
$ioa_meta_data['title'] = get_the_title();
} else {
$ioa_meta_data['title'] = get_the_title($id);
$ioa_options = get_post_meta($id, 'ioa_options', true);
}
if ($ioa_options == "") {
$ioa_options = array();
}
$page_layout = $page_sidebar = '';
if (isset($ioa_options['page_layout'])) {
$page_layout = $ioa_options['page_layout'];
}
if (isset($ioa_options['page_sidebar'])) {
$page_sidebar = $ioa_options['page_sidebar'];
}
$ioa_meta_data['template_mode'] = 'wp-editor';
if ($page_layout == "") {
if (isset($super_options[SN . '_page_layout']) && trim($super_options[SN . '_page_layout']) != '') {
$page_layout = $super_options[SN . '_page_layout'];
} else {
$page_layout = 'full';
}
if (isset($post) && $post->post_type == "post") {
if (isset($super_options[SN . '_post_layout']) && $super_options[SN . '_post_layout'] != '') {
$page_layout = $super_options[SN . '_post_layout'];
} else {
$page_layout = 'left-sidebar';
}
}
}
$ioa_meta_data['layout'] = $page_layout;
$ioa_meta_data['sidebar'] = $page_sidebar;
$flag = true;
if (IOA_WOO_EXISTS && is_shop()) {
$flag = false;
}
if (IOA_WOO_EXISTS && is_product_category()) {
$flag = false;
$ioa_meta_data['sidebar'] = $super_options[SN . '_woo_category_sidebar'];
$ioa_meta_data['layout'] = $super_options[SN . '_woo_category_layout'];
$ioa_meta_data['title'] = single_term_title('', false);
}
if (IOA_WOO_EXISTS && is_product_tag()) {
$flag = false;
$ioa_meta_data['sidebar'] = $super_options[SN . '_woo_tag_sidebar'];
$ioa_meta_data['layout'] = $super_options[SN . '_woo_tag_layout'];
$ioa_meta_data['title'] = single_term_title('', false);
}
if (is_tax()) {
$ioa_meta_data['title'] = single_term_title('', false);
}
if ($flag) {
if (is_author() || is_search() || is_tag() || is_category() || is_archive()) {
$ioa_meta_data['layout'] = 'right-sidebar';
}
if ((is_author() || is_search() || is_tag() || is_category() || is_archive() || is_home()) && !(IOA_WOO_EXISTS && is_shop())) {
if ((is_author() || is_search() || is_tag() || is_category() || is_archive()) && $flag) {
$ioa_meta_data['layout'] = 'right-sidebar';
}
if (is_archive()) {
$ioa_meta_data['title'] = "";
if (is_day()) {
$ioa_meta_data['title'] = __('Daily Archives:', 'ioa');
} elseif (is_month()) {
$ioa_meta_data['title'] = __('Monthly Archives: ', 'ioa');
} elseif (is_year()) {
$ioa_meta_data['title'] = __('Yearly Archives: ', 'ioa');
} elseif (is_tax()) {
$ioa_meta_data['title'] = single_term_title('', false);
} else {
$ioa_meta_data['title'] = __('Archives', 'ioa');
}
$show_title = "yes";
}
//.........这里部分代码省略.........
示例8: array_merge
if (strpos($Directory, '/_') === false) {
$Return = array_merge($Return, globRecursive($Directory . '/' . basename($Pattern), $Flags));
}
}
// FOREACHDIRECTORY
return $Return;
}
$translation_files = globRecursive(__DIR__ . '/../lang/*/*.json');
$result['invalid_files'] = 0;
$result['valid_files'] = 0;
$result['errors'] = array();
foreach ($translation_files as $filename) {
$shortname = translationFilename($filename);
$error = false;
// Validate JSON
if (!isJson($filename)) {
$result['invalid_files']++;
$result['errors'][] = $shortname . " => Invalid JSON";
continue;
}
// Validate all HTML tags have an open tag and close tag in same string
$values = array_values(json_decode(file_get_contents($filename), TRUE));
foreach ($values as $i => $value) {
$line_number = $i + 1;
// Translation number in transifex. Add 1 for JSON line number
preg_match_all("/\\<([a-z0-9]+)\\s?[^\\<]*?(?<!\\/)\\s*\\>/i", $value, $open_tags);
preg_match_all("/\\<\\/([a-z0-9]+)\\s?[^\\<]*?(?<!\\/)\\s*\\>/i", $value, $close_tags);
foreach ($open_tags[1] as $oi => $open_tag) {
foreach ($close_tags[1] as $ci => $close_tag) {
if (strtolower($open_tag) === strtolower($close_tag)) {
unset($close_tags[1][$ci]);
示例9: addAction
/**
* 添加数据集合的索引
*
* @author young
* @name 添加数据集合的索引
* @version 2013.12.22 young
*/
public function addAction()
{
$keys = $this->params()->fromPost('keys', '');
if (!isJson($keys)) {
return $this->msg(false, 'keys必须符合json格式,例如:{"index_name":1,"2d":"2d"}');
}
$keys = Json::decode($keys, Json::TYPE_ARRAY);
if (!is_array($keys) || empty($keys)) {
return $this->msg(false, '请检查$keys是否为空');
}
$keys = $this->filterKey($keys);
// 检测字段是否都存在
if (!$this->checkKeys(array_keys($keys))) {
return $this->msg(false, '键值中包含未定义的字段');
}
if (!$this->_targetCollection->ensureIndex($keys, array('background' => true))) {
return $this->msg(false, '创建索引失败');
}
$datas = array();
$datas['keys'] = Json::encode($keys);
$datas['collection_id'] = $this->_collection_id;
$this->_model->insert($datas);
return $this->msg(true, '创建索引成功');
}
示例10: ordersAction
function ordersAction()
{
try {
$user = !empty($this->_params[0]) ? $this->_params[0] : false;
$id = !empty($this->_params[1]) ? $this->_params[1] : false;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (!$user) {
throw new Exception("Inica el nombre e usuario", 1);
}
extract($_POST);
$productos = isJson($productos) ? json_decode(stripslashes($productos), true) : $productos;
$estado = isJson($estado) ? json_decode(stripslashes($estado), true) : $estado;
$hash_compra = md5(uniqid(time()));
$isValidOrder = isset($productos) && !empty($productos) && !empty($estado) && isset($estado);
foreach ($productos as $producto) {
$check = $this->product->productoTallaColor($producto['idproducto'], $producto['talla'], $producto['color']);
if (empty($check)) {
throw new Exception("No existe la relacion del producto\n {$producto['idproducto']}\n con a talla {$producto['talla']} y color {$producto['color']}", 1);
}
}
if ($isValidOrder) {
$idorder = $this->clients->save(array("hash_compra" => $hash_compra, "estado" => $estado, "username" => $user), "compras");
foreach ($productos as $producto) {
$isValidColor = $this->color->toArray($producto['color']);
$isValidSize = $this->size->toArray($producto['talla']);
if (empty($isValidColor)) {
try {
$this->color->save(array("idcolor" => $producto['color']));
} catch (Exception $e) {
throw new Exception("El color no es válido", 1);
}
}
if (empty($isValidSize)) {
try {
$this->size->toArray(array("idtalla" => $producto['talla']));
} catch (Exception $e) {
throw new Exception("La talla no es válida", 1);
}
}
try {
$this->clients->save(array("idcompra" => $idorder, "idproducto" => $producto['idproducto'], "cantidad" => $producto['q'], "username" => $user, "idtalla" => $producto['talla'], "idcolor" => $producto['color']), "compras_productos_tallas_colores");
} catch (Exception $e) {
echo $e->getMessage();
return;
}
}
$res = array('code' => 200, 'Msg' => "OK", 'order' => $idorder);
echo json_encode($res);
return;
}
throw new Exception("Parametros POSTS incorrectos", 1);
}
$pedidos = $this->clients->getOrders($user, $id);
echo json_encode($pedidos);
} catch (Exception $e) {
$error = array('error' => 400, 'errorMsg' => $e->getMessage());
echo json_encode($error);
}
return;
}
示例11: foreach
}
}
// add joined classes to $dataobject
foreach ($joinObjs as $className => $classData) {
$relObj = $dataobject->getFKDefinition($className);
if ($joinSettings[$className]['type'] == 'file' && $classData['error'] == 4) {
$hasData = false;
} else {
$hasData = array_filter($classData);
}
if ($relObj && $hasData) {
$relClass = $relObj['class'];
$relCardinality = $relObj['cardinality'];
$addObj = $modx->newObject($relClass);
foreach ($classData as $field => $value) {
if (!empty($value) && isJson($value)) {
$addObj->fromJson($value);
} elseif (is_array($value)) {
$value = getArrayFormat($value);
$addObj->set($field, $value);
} else {
$addObj->set($field, $value);
}
}
switch ($relCardinality) {
case 'one':
$dataobject->addOne($addObj);
break;
case 'many':
$dataobject->addMany($addObj);
break;
示例12: bulkImport
//.........这里部分代码省略.........
* @apiError ProductNotFound The id of the Product was not found.
*
* @apiErrorExample Error-Response:
* HTTP/1.1 404 Not Found
* {
* "error": "ProductNotFound"
* }
*
* @apiError RouteNotFound That route was not found on the server.
*
* @apiErrorExample Error-Response:
* HTTP/1.1 404
* {
* "error": "RouteNotFound"
* }
*/
public function bulkImport()
{
$results = array();
$request = $this->di->get('request');
$data = $request->getPost();
$processCompany = $processBrand = $processChannel = $processArea = 1;
if (!empty($data)) {
$product = new Products();
$productId = $product->id;
$metaData = new Memory();
$columns = $metaData->getColumnMap($product);
$channelId = isset($data['channelId']) ? $data['channelId'] : '';
$upload = isset($data['data']) ? $data['data'] : '';
$channel = Channels::findFirstById($channelId);
if (!$channel) {
throw new HTTPException("Not found", 404, array('dev' => 'The requested channel does not exist.', 'internalCode' => 'P1000', 'more' => ''));
}
if (isJson($upload) && !empty($channelId)) {
$productData = $brandData = $areaData = $companyData = array();
$companyParams = $brandParams = $channelParams = $productParams = array();
$channelAlias = $channel->alias;
$errors = '';
$upload = json_decode($upload, true);
if (!empty($upload)) {
for ($i = 0; $i < count($upload); $i++) {
$productInformation = $upload[$i];
$company = Companies::findFirstByName($productInformation['companyName']);
if ($company) {
$companyId = $company->id;
$processCompany = 0;
} else {
$company = new Companies();
$schemaFile = $this->schemaDir . $this->getDI()->getConfig()->application->jsonSchema->companies;
$output = readJsonFromFile($schemaFile, $this);
if (!empty($output)) {
$properties = $output['properties'];
foreach ($properties as $key => $value) {
switch ($key) {
case 'options':
continue 2;
break;
case 'name':
$companyParams[$key] = $productInformation['companyName'];
break;
default:
$companyParams[$key] = !empty($productInformation[$key]) ? $productInformation[$key] : '';
break;
}
}
}
示例13: r145
/**
* Store plugins info and config as json data instead of serialized data
*
* @return array SQL statements to be executed
*/
protected function r145()
{
$sqlUdp = array();
$stmt = execute_query('SELECT plugin_id, plugin_info, plugin_config FROM plugin');
if ($stmt->rowCount()) {
$db = iMSCP_Database::getRawInstance();
while ($row = $stmt->fetchRow(PDO::FETCH_ASSOC)) {
if (!isJson($row['plugin_info'])) {
$pluginInfo = $db->quote(json_encode(unserialize($row['plugin_info'])));
} else {
$pluginInfo = $db->quote($row['plugin_info']);
}
if (!isJson($row['plugin_config'])) {
$pluginConfig = $db->quote(json_encode(unserialize($row['plugin_config'])));
} else {
$pluginConfig = $db->quote($row['plugin_config']);
}
$sqlUdp[] = "\n\t\t\t\t\tUPDATE\n\t\t\t\t\t\tplugin\n\t\t\t\t\tSET\n\t\t\t\t\t\tplugin_info = {$pluginInfo}, plugin_config = {$pluginConfig}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tplugin_id = {$row['plugin_id']}\n\t\t\t\t";
}
}
return $sqlUdp;
}
示例14: validateParams
public function validateParams($type = '', $params = array(), $content = '')
{
$_test = '';
$_content = isJson($content) ? json_decode($content, true) : $content;
switch ($type) {
case 'API_LOGIN':
case 'API_COUNT_CREDITS':
case 'FILE':
case 'GET_PROCESS_STATUS':
case 'CREATE_BY_URL':
if (count($params) == 0) {
throw new Exception("Error: no response headers - wrong implementation");
}
$_test = $this->parseHeaders($params);
$_responseCode = $_test[$this->constants['RESPONSE_CODE']];
$_foundError = false;
if (isset($_test[$this->constants['COPYLEAKS_ERROR_HEADER']])) {
$_errCode = $_test[$this->constants['COPYLEAKS_ERROR_HEADER']];
$_error = new ErrorHandler($_errCode, $_content);
$_foundError = true;
throw new Exception("Error code: " . $_errCode . ", " . $_content['Message']);
}
if ($_responseCode !== 200) {
$_foundError = true;
// print_r($_content);die();
if (isset($_content['Message'])) {
throw new Exception("Response code: " . $_responseCode . ", " . $_content['Message']);
} else {
throw new Exception("Response code: " . $_responseCode . ", " . $_content);
}
}
return array('has_error' => $_foundError, 'response' => $_content, 'response_code' => $_responseCode);
// break;
// break;
default:
throw new Exception('INCORRECT VALIDATION TYPE');
}
}
示例15: formatData
/**
* 数据库定义类型值的格式化转换函数
*
* @param mixed $value
* @param string $type
* @param string $key
* @throws \Zend\Json\Exception\RuntimeException
* @return string
*/
function formatData($value, $type = 'textfield', $key = null)
{
switch ($type) {
case '_idfield':
break;
case 'numberfield':
$value = preg_match("/^[0-9]+\\.[0-9]+\$/", $value) ? floatval($value) : intval($value);
break;
case 'datefield':
if (!$value instanceof \MongoDate) {
$value = preg_match("/^[0-9]+\$/", $value) ? new \MongoDate(intval($value)) : new \MongoDate(strtotime($value));
}
break;
case '2dfield':
$value = is_array($value) ? array(floatval($value['lng']), floatval($value['lat'])) : array(0, 0);
break;
case 'md5field':
$value = trim($value);
$value = preg_match('/^[0-9a-f]{32}$/i', $value) ? $value : md5($value);
break;
case 'sha1field':
$value = trim($value);
$value = preg_match('/^[0-9a-f]{40}$/i', $value) ? $value : sha1($value);
break;
case 'boolfield':
$value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
break;
case 'arrayfield':
if (!is_array($value) && is_string($value)) {
$value = trim($value);
if (!empty($value)) {
if (!isJson($value)) {
throw new \Zend\Json\Exception\RuntimeException($key);
}
try {
$value = Json::decode($value, Json::TYPE_ARRAY);
} catch (\Zend\Json\Exception\RuntimeException $e) {
throw new \Zend\Json\Exception\RuntimeException($key);
}
}
}
break;
case 'documentfield':
if (!is_array($value) && is_string($value)) {
$value = trim($value);
if (!empty($value)) {
if (!isJson($value)) {
throw new \Zend\Json\Exception\RuntimeException($key);
}
try {
$value = Json::decode($value, Json::TYPE_ARRAY);
} catch (\Zend\Json\Exception\RuntimeException $e) {
throw new \Zend\Json\Exception\RuntimeException($key);
}
}
}
break;
default:
$value = trim($value);
break;
}
return $value;
}