Can I run PHP in Java? - php

I'm trying to make a form builder. I'm using SpringMVC.
I found this good form builder written in jQuery and PHP. Jquery Formbuilder
It converts an existing form(in DB) into JSON/XML and then passes it on for displaying. How can I achieve that in Spring? Is there a way I can reuse this plugin? Or use the PHP code inside Java directly?
Or is there a simpler way? Is there a similar plugin in Java?
Please guide.

You can use PHP code in Java with Quercus but it seems like a sledgehammer to crack a nut. Perhaps a simpler approach would be a PHP front end, populated by calls to a Java back-end

Related

Filtering and displaying mySQL Data on Webpage via Python? PHP?

I'd like to build a website that reads data from a database, lets me filter that data with different Frontend dropdown-filters and presents me the filtered data in a table shown on the Webpage.
In addition I'd like to have the possibility to use that data further to store it into some file, or use it in a python script that handles that data further.
Should I build the webpage using PHP or what would you recommend me?
I'm new on this area so I don't know much about website interaction yet, just have some experience writing python scripts until now.
Thank you for advices.
It depends on how familiar you are with PHP or Python. If you are new to both, I recommend you to start with PHP. If you are familiar with Python, I recommend you to use Flask or Django to make your project.

What templating languages are suitable for JS and PHP?

I'm looking for a templating "language" that works for both PHP and JS. I had a look at Mustache (has a very limited "if") and a few other like jquery-tmpl-php. So far but none of these seem to fulfil all my criteria:
Works with data provided by JSON (array, map, literal)
Has an "if" statement that can at least check if
a key in a map exists
a list element is first/last/odd/even
a value is equal to a literal
Can iterate over a list (iterating over keys in a map would be a bonus)
The same template and data generates exactly the same result with PHP and JS
Fast enough (I know, it's a bit vague)
Preferably no compiling step
Bonus: a nice way to "pluralize" texts and basically everything that makes i18n easier
Not smarty :)
I appreciate any ideas, suggestions or tips
Thanks,
Marek
I just wrote this whole post up only to re-read your question and see "not Smarty" :P . I'll just say I looked around for a while for a JS and PHP template library and Smarty seemed like the best option for me. You say Mustache is not enough. The only other one that comes to mind with both JS and PHP functionality is Haml.
Original:
I don't have a ton of experience with this yet but I've started using Smarty PHP templates. I create one Smarty template and send JSON to the client for Ajax requests. I then use this JS Smarty engine for client-side processing. If the client does not support Javascript, I can gracefully degrade by just sending the PHP associated array to the Smarty renderer server-side rather than sending it to the JSON parser. Still uses same .smarty file, working fairly well so far and I think I'm going to keep using this methodology for the rest of my project.

advice on php parsing

I am using phpTumblr, a wrapper around the tumblr blog api that allows you to access posts via php.
I want the site to display new posts dynamically, so I am using php to write html code. I find myself writing things like print(blablabla); or print(); ... and so on, and setting the header of the document to text/html, so that the browser would read it as html.
This just seems to me like a kind of ugly hack, and I was wondering if most dynamic pages are set up in this way, or are there different ways to convert php objects(say arrays) automatically into html tags. So far it doesnt seem like there are any.) maybe i have to be using some CMS software?
Any advice would be great.
Thanks
I believe what you're describing is known as a template engine. It essentially separates the logic from the UI, and allows you to write dynamic pages without an excessive number of print or echo statements.
For PHP, I would recommend Smarty, but Google can also help you with finding alternative ones if you find you don't like it.
PHP is a language in which you can do alot of different things and one of them is to send output to browsers. So if you want to print an array as HTML code , write a PHP function for it. PHP has NOTHING to do with HTML tags directly.
Like the above post mentions you can use Smarty templating engine ... BUT then you will need to learn the smarty language to print the array :)
All scripting languages work in this way. So lets say if any xyz language supports a function called print_array_as_html($array) .... then observe that it is a function. That's the idea of having functions/methods in a language , extend the functionality to get what you need.

calling php function from html

i'm a beginner to php. i need to use php function which process some other pages and to display
dynamic result as javascript when a HTML button click is triggered .Is it possible?...
Yes. This is possible through a collection of technologies known as AJAX, i.e. using Javascript's asynchronous communication ability.
There are already a number of pre-built libraries that allow you to do this with ease. One of the most common is Prototype, also just google AJAX and you will find hundereds of libraries, tutorials and guides to help you.
Jamie Lewis's answer is a good one, but I will say that he is addressing to JavaScript while answering. I think the pure PHP solution is following:
You create a PHP file (myFile.php) where you get some arguments with GET method. And Your HTML form should have a button that calls following:
myFile.php?agrument1=10&argument2=20
SO HTML will pass arguments to your PHP file and you should get that arguments and call a function with that arguments.
For more details see (sending arguments with GET/POST methods ).

Any PHP -> jQuery libraries out there?

Have any bridge libraries been developed for PHP that provide access to the jQuery framework? Ideally it would be nice to have something fairly extensible so that creating jQuery-based content using PHP code would be fairly easy and customizeable. Does such a thing exist yet?
pquery
jqpie
jquery-php
There's a warmup list.
So far I've found one that seems to fit the description. I haven't tried it out yet, so if anyone has any feedback or experience with this or other ones don't hesitate to post!
PQuery
jQPie might be what you're after.
What can jQPie do?
Easily request and process data from php using $.getJSON
Inject php generated html into elements using $.(element).load
Call php functions directly from your web pages using $.jqpie
Call jQuery from php in respond to $.jqpie calls
Advanced autocomplete using jqpie_complete
QueryPath (http://querypath.org) is a full implementation of the jQuery DOM/XML/HTML part of jQuery. QueryPath has full CSS 3 selector support (including the stuff jQuery doesn't have, like XML namespace support). It also comes with DB tools, where you can run queries and have the results inserted into the query object. And it has a template engine, too. Like jQuery, you can write custom extensions very easily.
But it definitely takes advantage of its server-side status.
The main project page is at https://fedorahosted.org/querypath. You can download it there (and see lots of examples, including RSS and SVG manipulation).
Integrating with jQuery, then, can be done easily by sending XML data of many sorts down to jQuery. (You could probably send JSON, too... never tried.) And since the server side code and the client side code both look the same, there's less of a need to learn two totally different toolkits.

Categories