Re:Learn PHP – Free interactive PHP tutorial
by captainmuon on Tuesday November 26, 2013 @09:38AM
(#6801470)
Actually the ability to mix PHP and "HTML" is the only reason I still use PHP occasionally. Sometimes, I have a plain-text file, and would like to use variables or simple loops in it. The best way to do this is PHP!
For example, say I want to plot a couple of data columns with gnuplot (an open source plotting program) into several images. I can write a PHP script "myplot.plt.php" that generates a gnuplot script (untested):
set terminal png enhanced
<?php
for ($i = 2; $i <= 4; $i++) {
$outputfile = "plot$i.png"
echo <<EOT
set output "$outputfile"
plot "data.txt" u 1:$i
EOT;
}
?>
and then invoke it from gnuplot with
load "< php myplot.plt.php"
This is a stupid example, but it gets really powerful when you dynamically calculate labels, element positions, etc.. PHP may be a crappy language for web development, but it is a really nice macro language, and has really powerful string processing features, making it ideal for this kind of hack.
For example, say I want to plot a couple of data columns with gnuplot (an open source plotting program) into several images. I can write a PHP script "myplot.plt.php" that generates a gnuplot script (untested):
and then invoke it from gnuplot with This is a stupid example, but it gets really powerful when you dynamically calculate labels, element positions, etc.. PHP may be a crappy language for web development, but it is a really nice macro language, and has really powerful string processing features, making it ideal for this kind of hack.