Ahhhhh PHP you evil dog...

sumdeus on 2004-03-18T07:59:56

Been quite busy lately using PHP--a mortal sin, but a necessary sin. Gotta get paid. In using it more and more however, I've become sincerely agitated over an increasing number of things:

  1. If I have to write ereg_* for a regular expression one more time I'm going to barf.
  2. All of the templating solutions are slow. Yeah, I know about caching the page, but I want more speed!
  3. Can you say CPAN? The PHP version of cpan is googling for code... sad.
  4. <? ... what the hell is \<?...
  5. I even miss the giant CGI.pm module...
What I need is a to be able to write Perl code and it's translated into php by some sort of fancy shmancy translator. Ah, a dream come true. Be glad you're hacking it in Perl.


Perl in HTML in PHP

Juerd on 2004-03-18T09:55:03

<?$x='PLP::Tie::Print::PRINT';$w=escapeshellarg($_SERVER[SCRIPT_FILENAME]);
$z= preg_split("/\n\n/",`perl -e'my\$f=shift;use PLP;\$ENV{PATH_TRANSLATED}=
\$f;my\$z=\\&$x;*$x=sub{*$x=\$z;PLP::sendheaders};P LP::everything' $w 2>&1`
,2);foreach(preg_split("/\n/",$z[0])as$y)header($y);echo$z[1];exit?><::&g t;
  <html>
<head>
<title>A PLP (Perl-in-HTML) document in PHP!</title>
</head>
<: BEGIN { $header{'Content-Type'} = 'text/html; charset="US-ASCII"'; } :>
<body>
<p>
It works! Let me show you with <tt>&lt;: print "See?&lt;br&gt;" for 1..5 :&gt;
</tt>
</p>
<p>
<: print "See?<br>" for 1..5 :>
</p>
<p>
And some data dumping:
</p>
<p><pre>
<:
    use Data::Dumper;
    print Dumper([ `ls -l` ]);
:>
</pre></p>
<p>
YAY!
</p>
<p>
There's no POST content available this way, though. Oh, and it's slow because of the forking.
</body>
</html>
Last line of PHP should end in, without spaces: questionmark, greaterthan, lessthan, colon, colon, greaterthan. But this site HTML encodes first and then adds spaces. Not the way to go, especially with code. I see that it also put a space in "PLP" somewhere. Ah well, you'll figure it out.

Re:Perl in HTML in PHP

sumdeus on 2004-03-18T16:19:02

There mere fact that this exists is both terrifying and intriguing. However you say that there's no POST content and it is terribly slow, not quite what I was looking for since I need to be using quite a bit of POST data and I need the site to be ultra fast.

I am going to continue to look at this just because i find it interesting. Thanks for the heads up on this, much appreciated.

Re:Perl in HTML in PHP

Juerd on 2004-03-19T00:01:21

You could hack POST support into it. It's just a proof of concept and I didn't bother to do such a thing.

If you need your site to be ultra fast, why the heck use PHP? Try PLP or if you can your own PerlHandler.

PHP and state of sin.

n1vux on 2004-03-18T23:13:53

I also have sinned.

I tried to talk the operator of a dot-org that wanted dynamic content and templates to install slashcode and some other Perl templatey stuff, but he was already using PHP for his Photo Gallery and other projects, alas. With the built-in MYSQL hookds it's not half bad, and it's *almost* Perl ... for what it's good for, we shouldn't need ereg_whatever_match very often. *sigh*.

The website is PHP fronting MYSQL for dynamic content. Currently updates are still manual SQL, eventually we might add a GUI, but volume isn't so high it's a bother. Originally it was static pages generated by perl -MText::Template from fielded text files, but I needed something a little more plausible. I do the offline preprocessing for the graphics in Perl still. Maybe later I'll give him a Perl DBI+GD CGI to make them dynamic too ... later.

If PHP comes out with a CRUD screen generator in the next release, that understands foreign keys somewhat, I'd be happy.

Next time I do a dot.org website, if they don't want MASON, they can find someone else ... I tell myself ;-)

Bill
Editor of ema.arrl.org FD Directory among others.

Re:PHP and state of sin.

sumdeus on 2004-03-18T23:25:15

It's nice to hear from someone else with similar woes. Hardcore Mason user eh? I think I'll stick with my TT, hasn't let me down so far.

*sigh* back to the php world...

Bless me father for I too have sinned

WebDragon on 2004-03-20T00:56:14

However I was lucky enough to be able to code the back end admin interface with perl/DBI,DBD::mysql/CGI.pm/CSS before having to diddle with the front end PHP/CSS/Javascript

SO far it's all coming together rather well, but like someone else here said, if I have to write preg_match* or ereg_match* one more damn time, I swear to god I'm gonna kill -9 /dev/universe.

*sigh* why the hell does it have to be so similar to perl? I'd be fine if it were widely different. and the slight differences are a major PITA.

continue in php means next in perl.
there is NO SUCH THING as a continue block.
break in php means last in perl.

crap like this.

I hear php was originally based on perl, and if so why the crapulous miasma of hell did they have to change it so much?

there's not even an 'unless' nor can I change the ordering of if statements

I can't do

blah($attr) unless $row->id == $whatever;
or
blah($attr) if !($row->id == $whatever);
or even
unless ($row->id == $whatever) { blah($attr);}

I gotta do

if ( !($row->id == $whatever) ) {
      blah($attr);
}

messy, very very messy. AND ugly as &*^#$^.

shoot me now. you'd be doing me a favor.