POV-Ray : Newsgroups : povray.off-topic : Lamp me one Server Time
14 Nov 2024 16:17:27 EST (-0500)
  Lamp me one (Message 1 to 10 of 26)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Invisible
Subject: Lamp me one
Date: 5 Feb 2008 07:57:15
Message: <47a85d2b@news.povray.org>
I just learned PHP. I feel unclean...

[Seriously. The *introductory tutorial* is littered with warnings about 
obscure functionallity which used to be broken but now isn't, and 
strange features that used to work one way but now work a slightly 
different way. I'm almost scared to write anything with this...]

Still, for some reason PHP is extremely popular, so I guess it would be 
useful to learn it. Certainly if most of the complex control logic is 
implemented in a real programming language, PHP looks quite good for 
stitching complex blocks of HTML together with relative ease.

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

From: Invisible
Subject: Re: Lamp me one
Date: 5 Feb 2008 09:27:35
Message: <47a87257@news.povray.org>
Invisible wrote:
> I just learned PHP. I feel unclean...

And here's a small pointless toy I just developed...

<html>
<head>
   <title>PHP Test #4 (Output)</title>
</head>
<body>

<h1>PHP Test #4 (Output)</h1>
<p>
<a href="Test4-In.html">Return to input form</a>
</p>

<h2>Input</h2>
<pre><?php echo htmlspecialchars($_POST['code']); ?></pre>
<p>Length: <?php echo strlen($_POST['code']); ?> characters.</p>

<h2>Frequency Table</h2>
<?php
$table = array();
$in = $_POST['code'];

for ($pos=0; $pos < strlen($in); $pos++)
{
   $symbol = $in[$pos];
   if (isset($table[$symbol])) $table[$symbol] = $table[$symbol] + 1;
   else $table[$symbol] = 1;
}
?>

<table border="1">
   <tr>
     <th>Symbol</th>
     <th>Count</th>
     <th>Probability</th>
     <th>Bits</th>
   </tr>
<?php
foreach ($table as $symbol => $count)
{
   echo '<tr><td align="center">‘<code>';
   echo htmlspecialchars($symbol);
   echo '</code>’</td><td align="right">';
   echo $count;
   echo '</td><td align="right">';
   echo (int)($count / strlen($in) * 100);
   echo '%</td><td align="right">';
   echo abs(log($count / strlen($in)) / log(2));
   echo '</td></tr>';
   echo "\n";
}
?>
   <tr>
     <td align="center">Total</td>
     <td align="right"><?php echo strlen($in); ?></td>
     <td align="right">100%</td>
     <td align="right">0</td>
   </tr>
</table>

</body>
</html>

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

From: Warp
Subject: Re: Lamp me one
Date: 5 Feb 2008 09:56:47
Message: <47a8792b@news.povray.org>
Invisible <voi### [at] devnull> wrote:
> Still, for some reason PHP is extremely popular, so I guess it would be 
> useful to learn it.

  You won't like it. It looks a bit like C++.

-- 
                                                          - Warp


Post a reply to this message

From: Warp
Subject: Re: Lamp me one
Date: 5 Feb 2008 09:58:14
Message: <47a87982@news.povray.org>
Invisible <voi### [at] devnull> wrote:
> And here's a small pointless toy I just developed...

  Don't mix HTML and PHP. That's just asking for maintenance nightmares.

>    echo '<tr><td align="center">‘<code>';
>    echo htmlspecialchars($symbol);
>    echo '</code>’</td><td align="right">';
>    echo $count;
>    echo '</td><td align="right">';
>    echo (int)($count / strlen($in) * 100);
>    echo '%</td><td align="right">';
>    echo abs(log($count / strlen($in)) / log(2));
>    echo '</td></tr>';
>    echo "\n";

  You don't need to make a separate 'echo' for each of those things.

-- 
                                                          - Warp


Post a reply to this message

From: Invisible
Subject: Re: Lamp me one
Date: 5 Feb 2008 10:04:38
Message: <47a87b06@news.povray.org>
Warp wrote:

>   Don't mix HTML and PHP. That's just asking for maintenance nightmares.

I thought that was the design goal of PHP?

[Er, to be mixed with HTML, that is.]

>>    echo '<tr><td align="center">‘<code>';
>>    echo htmlspecialchars($symbol);
>>    echo '</code>’</td><td align="right">';
>>    echo $count;
>>    echo '</td><td align="right">';
>>    echo (int)($count / strlen($in) * 100);
>>    echo '%</td><td align="right">';
>>    echo abs(log($count / strlen($in)) / log(2));
>>    echo '</td></tr>';
>>    echo "\n";
> 
>   You don't need to make a separate 'echo' for each of those things.

You do if you only have a 40x40 character text window and a text editor 
which malfunctions on long lines...

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

From: Invisible
Subject: Re: Lamp me one
Date: 5 Feb 2008 10:05:35
Message: <47a87b3f$1@news.povray.org>
Warp wrote:
> Invisible <voi### [at] devnull> wrote:
>> Still, for some reason PHP is extremely popular, so I guess it would be 
>> useful to learn it.
> 
>   You won't like it. It looks a bit like C++.

Quoting somebody else:

   "Haskell is really bad - it makes you hate normal languages."

But then, I never really liked scripting languages much, and that was 
way before Haskell, so... ;-)

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

From: Warp
Subject: Re: Lamp me one
Date: 5 Feb 2008 10:36:30
Message: <47a8827c@news.povray.org>
Invisible <voi### [at] devnull> wrote:
> Warp wrote:

> >   Don't mix HTML and PHP. That's just asking for maintenance nightmares.

> I thought that was the design goal of PHP?

  Maybe it was, but in practice it's usually a bad idea. I have seen
horrible, horrible examples.

  This may be an acceptable exception:

<?php
  ... lots of PHP code here
?>

<html>
...
  <?php (something which calls the code above) ?>
...
</html>

> >   You don't need to make a separate 'echo' for each of those things.

> You do if you only have a 40x40 character text window and a text editor 
> which malfunctions on long lines...

  No you don't:

echo
 'hello ' .
 $user .
 ", how are you?\n";

  At least it saves you from writing 'echo' a million times.

-- 
                                                          - Warp


Post a reply to this message

From: Invisible
Subject: Re: Lamp me one
Date: 5 Feb 2008 10:45:35
Message: <47a8849f$1@news.povray.org>
Warp wrote:

>>>   Don't mix HTML and PHP. That's just asking for maintenance nightmares.
> 
>> I thought that was the design goal of PHP?
> 
>   Maybe it was, but in practice it's usually a bad idea. I have seen
> horrible, horrible examples.

I can imagine...

The PHP tutorial explains how you can do "really cool" things like this:

<?php if ($somecondition) { ?>

Lots of HTML here...

<?php } else { ?>

lots more HTML here...

<?php } ?>

Which... uh... well I can imagine it becoming messy quite fast.

>   This may be an acceptable exception:
> 
> <?php
>   ... lots of PHP code here
> ?>
> 
> <html>
> ...
>   <?php (something which calls the code above) ?>
> ...
> </html>

Yeah, that seems more like the model to follow. (In fact, some of the 
user comments I've seen suggest that all the "real code" should be in 
include files instead and just called from the HTML pages.)

>>>   You don't need to make a separate 'echo' for each of those things.
> 
>> You do if you only have a 40x40 character text window and a text editor 
>> which malfunctions on long lines...
> 
>   No you don't:
> 
> echo
>  'hello ' .
>  $user .
>  ", how are you?\n";

Ooo... you can do that?

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

From: Nicolas Alvarez
Subject: Re: Lamp me one
Date: 5 Feb 2008 10:51:34
Message: <47a88606$1@news.povray.org>

> Warp wrote:
>>   No you don't:
>>
>> echo
>>  'hello ' .
>>  $user .
>>  ", how are you?\n";
> 
> Ooo... you can do that?
> 

Yes, and you can also pass multiple arguments to 'echo' (ie. what Warp 
said, but with a comma instead of the concat operator). It's probably a 
millisecond faster to do it that way too.

http://blog.libssh2.org/index.php?/archives/28-How-long-is-a-piece-of-string.html


Post a reply to this message

From: Gilles Tran
Subject: Re: Lamp me one
Date: 5 Feb 2008 11:27:42
Message: <47a88e7e$1@news.povray.org>

47a87b06@news.povray.org...
> Warp wrote:
>
>>   Don't mix HTML and PHP. That's just asking for maintenance nightmares.
>
> I thought that was the design goal of PHP?

I second Warp. You can mix HTML and PHP in the same page but it's likely to 
turn into some horrible mess before you know it.
The trick is to build long text strings in PHP (that include the HTML tags 
and everything you want to see on screen) and then echo the result.

G.

-- 
**********************
http://www.oyonale.com
**********************
- Graphic experiments
- POV-Ray and Poser computer images
- Posters


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.