Last active
February 8, 2017 10:37
-
-
Save Namrud/c422c8bc348e7f0f71e2ac6fc4288fd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| ** JNX - JSON Based Library System For PHP | |
| ** Developer - Namrud Girma Wolde | |
| ** Version - 1.0 | |
| ** Website - http://m-live.me | |
| ** Contact - https://fb.me/mLIVEEternal | |
| ** | |
| ** EXPLANATION | |
| ** JSON is known to be light, cross-language and modern. | |
| ** Using this PHP Library simple JSON based databases could be created. | |
| ** If you have a simple web project and needed a simple database which | |
| ** handle simple operations this is the right library for you. | |
| ** Using this you can, read, write, update, create, delete, rename.. JSON Files. | |
| ** | |
| ** Pre-requisite: PHP Installation All Versions are supported i think | |
| ** JNX is the main class. All the examples below could be used Separetly or Together. | |
| ** Like everything else in the universe this Library works Logically. | |
| ** Use your imaginations and act like you know because, energy couldn't be created. | |
| ** | |
| ** This library has given no place for Security. | |
| ** In futher version i will come up with Security in mind. | |
| ** But for now .htaccess and ciphers could be used. | |
| */ | |
| //Make a Call to the Library | |
| require_once("jsonLibrary.php"); | |
| //Creating A JSON FILE | |
| JNX::createJ("newFile.json"); | |
| //Deleting A JSON FILE | |
| JNX::removeJ("newFile.json"); | |
| //Rename A JSON FILE | |
| JNX::renameJ("newFile.json", "renamedFile.json"); | |
| //Copy A JSON FILE | |
| JNX::copyJ("renamedFile.json", "Folder/renamedFile.json"); | |
| //Read A JSON FILE Raw | |
| $JSON = JNX::openJ("renamedFile.json", "readStringJ"); | |
| echo $JSON; | |
| //Read A JSON FILE Parsed | |
| $JSON = JNX::openJ("renamedFile.json", "readJ"); | |
| echo json_encode($JSON); | |
| //Write To A JSON FILE | |
| JNX::openJ("renamedFile.json", "writeJ", "['object1']", "string1"); | |
| JNX::openJ("renamedFile.json", "writeJ", "['object2']", array("Value1", "Value2", array("Value2 Sub1", "Value2 Sub2"))); | |
| JNX::openJ("renamedFile.json", "writeJ", "['object3']", false); | |
| //Delete From A JSON FILE | |
| JNX::openJ("renamedFile.json", "deleteJ", "['object3']"); | |
| //Remove Unreadable Characters from a String | |
| $string = JNX::openJ("renamedFile.json", "readStringJ"); | |
| $cleanedString = JNX::BOMJ($string); | |
| echo $cleanedString; | |
| //Remove Languages and Characters Other Than English | |
| $string = JNX::openJ("renamedFile.json", "readJ"); | |
| $cleanedString = JNX::cleanJ($string['object1']); | |
| echo $cleanedString; | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class JNX { | |
| //File Functions | |
| public static function createJ($var5){ | |
| $file04 = fopen($var5, "w"); | |
| fwrite($file04, ""); | |
| fclose($file04); | |
| } | |
| public static function removeJ($var6){ | |
| unlink($var6); | |
| } | |
| public static function renameJ($var7, $var8){ | |
| rename($var7, $var8); | |
| } | |
| public static function copyJ($var7, $var8){ | |
| copy($var7, $var8); | |
| } | |
| //Content Functions | |
| private static function readJ($var1){ | |
| return json_decode(file_get_contents($var1), true); | |
| } | |
| private static function readStringJ($var1){ | |
| return file_get_contents($var1); | |
| } | |
| private static function writeJ($var3, $var4, $var5){ | |
| $var6 = self::readJ($var3); | |
| eval("\$var6".$var4." = \$var5;"); | |
| $file02 = fopen($var3, "w"); | |
| fwrite($file02, json_encode($var6)); | |
| fclose($file02); | |
| } | |
| private static function deleteJ($var3, $var4){ | |
| $var5 = self::readJ($var3); | |
| eval("unset(\$var5".$var4.");"); | |
| $file03 = fopen($var3, "w"); | |
| fwrite($file03, json_encode($var5)); | |
| fclose($file03); | |
| } | |
| //String Functions | |
| public static function BOMJ($data) { | |
| if (0 === strpos(bin2hex($data), 'efbbbf')) { | |
| return substr($data, 3); | |
| }else{ | |
| return $data; | |
| } | |
| } | |
| public static function cleanJ($string, $incase="", $char="") { | |
| $cleanchar = ucwords(preg_replace('/[^A-Za-z0-9(.|!|,|:|(|)|_|%|$|{|}|?|+|=|-|#|@|\x2f|\x27|\x22|;|\x7c)\d ]+/i', '', $string)); | |
| $cleanchar3 = preg_replace('/\s+/', '', $cleanchar); | |
| if (strlen($cleanchar3) < $char) { | |
| $cleanchar3 = $cleanchar3; | |
| return $cleanchar3; | |
| } else { | |
| return $cleanchar; | |
| } | |
| } | |
| //Model Function | |
| static function openJ($var0, $var00, $var01 = null, $var02 = null){ | |
| if(file_exists($var0)){ | |
| return self::$var00($var0, $var01, $var02); | |
| }else{ | |
| echo $var0." - No Such File Exists.<br/>"; | |
| } | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment