a lib that can modify the php code via javascript
- it's built as Webassembly
- it's written in Go and uses z7zmey/php-parser
yarn add php-form
The full API for php-form is contained within the TypeScript declaration file
import {instance} from 'php-form'
(async () => {
const form = await instance()
let code = `<?php
$form_email = [
'label' => 'Email',
'value' => 'user1@example.com',
];
$form_name = 'billy'
`
const fields = await form.parse(code)
// [{name: '$form_email', label: 'Email', value: 'user1@example.com'}, {name: '$form_name', value: 'billy'}]
fields[0].value = 'user2@example.com'
fields[1].value = 'magic'
code = await form.stringify(fields)
// <?php $form_email = [
// 'label' => 'Email',
// 'value' => 'user2@example.com',
// ];
//
// $form_name = 'magic'
})