Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML>
- <html>
- <head>
- <title>Gen Object</title>
- <style>
- .error {
- color: #FF0000;
- }
- </style>
- </head>
- <body>
- <?php
- // define variables and set to empty values
- $nameErr = "";
- $name = "";
- if ($_SERVER ["REQUEST_METHOD"] == "POST") {
- if (empty ( $_POST ["name"] )) {
- $nameErr = "Name is required";
- } else {
- $name = test_input ( $_POST ["name"] );
- // check if name only contains letters and whitespace
- if (! preg_match ( "/^[a-zA-Z,]*$/", $name )) {
- $nameErr = "Only letters and comma allowed";
- }
- }
- }
- function test_input($data) {
- $data = trim ( $data );
- $data = stripslashes ( $data );
- $data = htmlspecialchars ( $data );
- return $data;
- }
- ?>
- <h2 align="center">Gen Object</h2>
- <p align="center">
- <span class="error">* Required field.</span>
- </p>
- <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
- <table bgcolor="#ecf0f1" align="center" width="60%" border="1" cellspacing="0">
- <tr align="center" bgcolor="#1abc9c">
- <td colspan="2"><b>Enter Name Object</b>
- </tr>
- <tr >
- <td >
- <textarea type="text" name="name" id="object" style="width: 900px; height: 200px;"><?php echo $name;?></textarea>
- <span class="error">* <?php echo $nameErr;?></span>
- </td>
- </tr>
- <tr bgcolor="#1abc9c" align="center">
- <td colspan="2"><input type="submit" name="submit" value="Gen Object"></td>
- </tr>
- </table>
- </form>
- <h2 align="center">Your Input:</h2>
- <table align="center">
- <tr align="left">
- <td >
- <textarea style="width: 900px; height: 400px;">
- <?php
- $str = "[" . $name . "]";
- $string = preg_replace ( '/\,/', "\",\"", $str );
- $string2 = preg_replace ( '/\[/', "[\"", $string );
- $string3 = preg_replace ( '/\]/', "\"]", $string2 );
- $string4 = trim ( preg_replace ( '/\s+/', ' ', $string3 ) );
- $arr = json_decode ( $string4 );
- for($i = 0; $i < count ( $arr ); $i ++) {
- $strcuoi= mb_ereg_replace("\"","", strtoupper ( $arr [$i] ));
- echo "public static final String " .$strcuoi . " = keys[" . $i . "]; ";
- }
- ?></textarea>
- </td>
- </tr>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement