get value - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of get value.php
- <?php
- $html = '
- <html>
- <head>
- </head>
- <body>
- </body>
- <script>
- var var1 = [{"key1":"value1","key2":"value2"}]
- ...
- </script>
- </html>
- ';
- $target_var = 'var1';
- preg_match('/var\s*'.$target_var.'\s*=\s*([^\]]+\])/i', $html, $matches);
- print_r($matches); //test match
- if(!empty($matches[1]))
- {
- $val = json_decode($matches[1]);
- print_r($val); //the value
- }
File Description
- get value
- PHP Code
- 12 May-2022
- 383 Bytes
You can Share it:
Latest PHP Pastes