I am interested in knowing the ways we can call/run Perl scripts in PHP.
You can use a simple Php Perl extension within the Php code. This will allow you to execute code and Perl variables,functions and instantiate objects.
$perl = new Perl();
$perl->require("test1.pl");
You can make use of
system
exec
backtick operator
Just like any other executable.
But avoid it, it's very inefficient. What do you want to achieve by doing it?
Use something like
system("/your/kewl/script.pl");
Related
What does USE do in php? I thought it was like include() but apparently I'm wrong. Could somebody point me to the php documentation on USE and maybe some example code?
use has two uses:
Namespaces
Anonymous Functions, aka Closures
I would like to execute a string as if it were PHP code.
An example would be:
$string='round(24.6,2)';
I would like to convert $string to executable syntax. Is there a way to do this?
eval()
is the function you want. But: eval() is evil!
You can use eval('round(24.6,2)'), but this is usually frowned upon for multiple reasons. Why do you want to do this?
Say I have a variable containing PHP code, can I include its content as if it was a normal PHP file ?
For example, the PHP code could be a class declaration.
You don't have a variable containing php code. You have a string.
You can execute a string as php with the evil eval function, but puppies AND kittens will die!
eval($your_variable);
Be aware about security holes!This is very dangerous and should NOT be based on user's input !
You could use eval to evaluate any code that you have in your string, however it is evil. What exactly are you trying to do?
I'm trying to use webspace provided by my university. They are currently using an outdated version of php, 5.1 I think. Anyway it doesn't have a json_encode function, however, I need a json_encode function (or equivalent) for my code to work.
So if anyone could explain to me the syntax for the return of the json_encode function or point me to a website that explains it nicely it'd be much appreciated.
Thanks
Don't reinvent the wheel: upgrade.php library.
http://pear.php.net/package/Services_JSON
Check here. It tells you to use require 'jsonwrapper.php'; at the start of your code in versions of PHP where json_encode is not available.
I would like to interface a php page to the linux command line program ping.
I realize that there are sanitation issues. Is there a builtin library or function that can take care of everything, or will I have to rely on regex parsers?
Do you mean escapeshellcmd and escapeshellarg?
do you mean to sanitize variable http://php.net/filter_var ?
good tutorial
http://www.phpro.org/tutorials/Filtering-Data-with-PHP.html