I'm writing a simple CMS for a friend and have a query regarding running perl or python scripts from within php and returning the output for use in a HTML page.
eg, the user inputs some text and submits it to the database. A script parses that text before it is saved. Then when it is a retrieved another script parses it before it is displayed.
I'm implementing Markdown via Markdown.pl and html2text via html2text.py.
Both of these scripts run and work ine on the command line. However I am having significant trouble getting them to work from within php.
I'm currently using "system()" to run them, but I can't work out how to use the output.
I want to write a function that a I pass a string to and it returns the parsed output.
eg,
Code: Select all
function html2text($string)
{
// parse text and return output
ob_start();
system("echo ".escapeshellarg($string)."|blah/html2text.py");
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
function text2html($string)
{
ob_start();
system("blah/Markdown.pl ".escapeshellarg($string));
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}