Skip to content

Commit b2c3592

Browse files
committed
IHF: is_json function added.
1 parent d02bcf9 commit b2c3592

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/json.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
if (!function_exists('is_json')) {
4+
function is_json($string, $return = false)
5+
{
6+
if (!is_string($string)) {
7+
return false;
8+
}
9+
10+
$data = json_decode($string);
11+
if (json_last_error() != JSON_ERROR_NONE) {
12+
return false;
13+
}
14+
15+
return ($return ? $data : true);
16+
}
17+
}

0 commit comments

Comments
 (0)