David David - 5 months ago 21
Perl Question

php / perl Experimenting with syntax "9"?

I'm currently just toying with PHP and it's syntax. But I am getting an random result.

My idea is to use perl to generate HTML and then replace certian keywords with PHP define. However playing with this, this is my idea for now


$lol = "Seriously, so I can enter text here from DB and stuff...";
function callback($buffer,$lol)

return (str_replace("MSG", "$lol", $buffer));


$html = shell_exec("/usr/bin/perl /fox/perl/simple.pl 2>&1");
print ($html);

$css = shell_exec("/usr/bin/perl /fox/perl/css.pl 2>&1");
print ($css);



print <<HTML;
<table width="auto" border="1" class="center" id="container" cellspacing="10">
<td id="main_content" width="auto" ><b>Baa! </b><br />
Well? what you doing here.. Baaa <br />
<br />


<br />

Now, the page renders perfectly, however where the string MSG exists, I get a result of 9

Well? what you doing here.. Baaa

Curious to what's causing nine to appear, I'm assuming i'm counting some sort of value but not sure what value and if I am, why 9? Is there another syntax I should be using to do such?

If I remove the declaration with a string ("MSG", "lol", $buffer) it behaves as it should. Replacing MSG with lol.



ob_start is not expecting incoming variables like $foo . As drew010 indicated, the format for your callback must be:

string handler ( string $buffer [, int $phase ] )

You can work around it in a couple of ways. For example:

ob_start(function($buffer) use ($lol) {
  return (str_replace("MSG", "$lol", $buffer));

or if you don't mind global variables:

function callback($buffer)
  global $lol;
  return (str_replace("MSG", "$lol", $buffer));