AI prompts
base on Use PHP code right within your React / Next.js App. With "use php"; ## Next.js `use php`
> [!NOTE]
> Check out **solidtime - The modern Open Source Time-Tracker** at [solidtime.io](https://www.solidtime.io)
Use PHP right inside of your Next.js project.
Just like `use server` (not really).
**You can watch how i made it [here](http://www.youtube.com/watch?v=EGOkjmyfL6E)**
[![Youtube Video about how this project was made](http://img.youtube.com/vi/EGOkjmyfL6E/0.jpg)](http://www.youtube.com/watch?v=EGOkjmyfL6E "Write PHP in Next.js/React Components")
You can use it in React Server Components just like this:
```javascript
return (
<button
formAction={async () => {
'use php'
(new PDO('mysql:host=localhost:3306;dbname=public', 'root', 'root'))
->prepare("INSERT INTO Bookmarks (slug) VALUES (?)")
->execute(array('new'));
}}>
Insert Bookmark
</button>
)
```
And if you want to it can even work with React Client Components
```javascript
// actions.js
'use server'
export async function phpHelloWorld() {
'use php'
print "Hello from PHP";
}
```
```javascript
// page.tsx
import {phpHelloWorld} from "../actions";
```
Yes this actually works. Trust me I wish it wouldn't too.
## Build
You can build the implementation by
```bash
npm run build
npm run start
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
If you want to try out the Database Example, you can use the docker-compose file provided in the repository.
after `docker-compose up -d` you need to create the database and table you want to insert into manually.
## Roadmap (Things that should be fixed but realistically it will never happen)
- [ ] There is a probably a way to fix that nasty preprocess step with [SWC Plugins]( https://swc.rs/docs/plugin/ecmascript/getting-started) which are still in Beta with Next.js and also I think they will switch builder anyways soon so what's the point really? But hey if anyone wants to do it feel free.
- [ ] I guess there is some hacky way to make props binding possible.
## Credits
Check out the original implementations by elnardu for C and Rust:
* https://github.com/elnardu/react-use-c
* https://github.com/elnardu/react-use-rust
## Disclaimer
*I hope I don't have to say this but: If you even in the slightest consider to use this in any application at all you are an absolute madperson and and should be locked out of the internet for the rest of your life, I hope you find some other fun activity, maybe gardening or woodwork.*
## Self-Promo
If you enjoyed this project and want to see more silly web development projects, you can follow me on [Twitter](https://twitter.com/bufferhead_), [Bluesky](https://bsky.app/profile/bufferhead.bsky.social) and [Youtube](https://www.youtube.com/@bufferhead_).
", Assign "at most 3 tags" to the expected json: {"id":"4574","tags":[]} "only from the tags list I provide: [{"id":77,"name":"3d"},{"id":89,"name":"agent"},{"id":17,"name":"ai"},{"id":54,"name":"algorithm"},{"id":24,"name":"api"},{"id":44,"name":"authentication"},{"id":3,"name":"aws"},{"id":27,"name":"backend"},{"id":60,"name":"benchmark"},{"id":72,"name":"best-practices"},{"id":39,"name":"bitcoin"},{"id":37,"name":"blockchain"},{"id":1,"name":"blog"},{"id":45,"name":"bundler"},{"id":58,"name":"cache"},{"id":21,"name":"chat"},{"id":49,"name":"cicd"},{"id":4,"name":"cli"},{"id":64,"name":"cloud-native"},{"id":48,"name":"cms"},{"id":61,"name":"compiler"},{"id":68,"name":"containerization"},{"id":92,"name":"crm"},{"id":34,"name":"data"},{"id":47,"name":"database"},{"id":8,"name":"declarative-gui "},{"id":9,"name":"deploy-tool"},{"id":53,"name":"desktop-app"},{"id":6,"name":"dev-exp-lib"},{"id":59,"name":"dev-tool"},{"id":13,"name":"ecommerce"},{"id":26,"name":"editor"},{"id":66,"name":"emulator"},{"id":62,"name":"filesystem"},{"id":80,"name":"finance"},{"id":15,"name":"firmware"},{"id":73,"name":"for-fun"},{"id":2,"name":"framework"},{"id":11,"name":"frontend"},{"id":22,"name":"game"},{"id":81,"name":"game-engine "},{"id":23,"name":"graphql"},{"id":84,"name":"gui"},{"id":91,"name":"http"},{"id":5,"name":"http-client"},{"id":51,"name":"iac"},{"id":30,"name":"ide"},{"id":78,"name":"iot"},{"id":40,"name":"json"},{"id":83,"name":"julian"},{"id":38,"name":"k8s"},{"id":31,"name":"language"},{"id":10,"name":"learning-resource"},{"id":33,"name":"lib"},{"id":41,"name":"linter"},{"id":28,"name":"lms"},{"id":16,"name":"logging"},{"id":76,"name":"low-code"},{"id":90,"name":"message-queue"},{"id":42,"name":"mobile-app"},{"id":18,"name":"monitoring"},{"id":36,"name":"networking"},{"id":7,"name":"node-version"},{"id":55,"name":"nosql"},{"id":57,"name":"observability"},{"id":46,"name":"orm"},{"id":52,"name":"os"},{"id":14,"name":"parser"},{"id":74,"name":"react"},{"id":82,"name":"real-time"},{"id":56,"name":"robot"},{"id":65,"name":"runtime"},{"id":32,"name":"sdk"},{"id":71,"name":"search"},{"id":63,"name":"secrets"},{"id":25,"name":"security"},{"id":85,"name":"server"},{"id":86,"name":"serverless"},{"id":70,"name":"storage"},{"id":75,"name":"system-design"},{"id":79,"name":"terminal"},{"id":29,"name":"testing"},{"id":12,"name":"ui"},{"id":50,"name":"ux"},{"id":88,"name":"video"},{"id":20,"name":"web-app"},{"id":35,"name":"web-server"},{"id":43,"name":"webassembly"},{"id":69,"name":"workflow"},{"id":87,"name":"yaml"}]" returns me the "expected json"