Is there any way to execute PHP code given by the user on a local server (for testing)?

  android, forms, localhost, nanohttpd, php

I am trying to develop an android app with the help of NanoHttpD library that locally runs a PHP server. By default, in index.html, I want to place a webpage that can be used to directly test raw php code entered by the user. Something like this Is there any simple way I can do it or any already available project that already does that well in a better way? Even a rough logic how can I go about things would do.

Source: Ask PHP