Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #7850 > unrolled thread
| Started by | "P E Schoen" <paul@peschoen.com> |
|---|---|
| First post | 2012-12-19 07:30 -0500 |
| Last post | 2012-12-19 13:23 -0500 |
| Articles | 13 — 6 participants |
Back to article view | Back to comp.lang.php
Using echo to run separate PHP script from HTML "P E Schoen" <paul@peschoen.com> - 2012-12-19 07:30 -0500
Re: Using echo to run separate PHP script from HTML Richard Yates <richard@yatesguitar.com> - 2012-12-19 07:02 -0800
Re: Using echo to run separate PHP script from HTML "P E Schoen" <paul@peschoen.com> - 2012-12-19 13:13 -0500
Re: Using echo to run separate PHP script from HTML Jerry Stuckle <jstucklex@attglobal.net> - 2012-12-19 15:05 -0500
Re: Using echo to run separate PHP script from HTML "P E Schoen" <paul@peschoen.com> - 2012-12-19 16:59 -0500
Re: Using echo to run separate PHP script from HTML Jerry Stuckle <jstucklex@attglobal.net> - 2012-12-19 17:50 -0500
Re: Using echo to run separate PHP script from HTML Luuk <luuk@invalid.lan> - 2012-12-19 21:23 +0100
Re: Using echo to run separate PHP script from HTML "P E Schoen" <paul@peschoen.com> - 2012-12-19 18:33 -0500
Re: Using echo to run separate PHP script from HTML Richard Yates <richard@yatesguitar.com> - 2012-12-19 17:24 -0800
Re: Using echo to run separate PHP script from HTML "Peter H. Coffin" <hellsop@ninehells.com> - 2012-12-19 14:32 -0600
Re: Using echo to run separate PHP script from HTML Jerry Stuckle <jstucklex@attglobal.net> - 2012-12-19 17:51 -0500
Re: Using echo to run separate PHP script from HTML The Natural Philosopher <tnp@invalid.invalid> - 2012-12-19 16:04 +0000
Re: Using echo to run separate PHP script from HTML "P E Schoen" <paul@peschoen.com> - 2012-12-19 13:23 -0500
| From | "P E Schoen" <paul@peschoen.com> |
|---|---|
| Date | 2012-12-19 07:30 -0500 |
| Subject | Using echo to run separate PHP script from HTML |
| Message-ID | <kasc1f$m0s$1@dont-email.me> |
I adapted a PHP script that presents a vertical bargraph showing a goal and
current value and percentage. It was from:
http://www.scriptygoddess.com/archives/2008/02/23/how-to-make-a-progressgoal-thermometer-like-bar-graph-with-php/
My adaption includes a text file for the goal and current value as well as
height and width. This "goalgraph.php" works OK:
<?php
$datafile = "goalgraphdata.txt";
if( !file_exists($datafile) ) {
$df = fopen( $datafile, "w" ) or die( "File Error" );
// cur, goal, height, width
fwrite( $df, "100\r\n50\r\n200\r\n25\r\n" );
fclose( $df );
}
if (isset($_GET['cur']) && isset($_GET['goal']) && isset($_GET['height']) &&
isset($_GET['width']) ) {
header("Content-type: image/png");
//setting the values we'll use in our script pulled in from GET
$height = trim($_GET['height']);
$width = trim($_GET['width']);
$goal = trim($_GET['goal']);
$current = trim($_GET['cur']);
$df = fopen( $datafile, "w" ) or die( "File Error" );
// cur, goal, height, width
fwrite( $df, "$current\r\n$goal\r\n$height\r\n$width\r\n" );
fclose( $df );
}
$df = fopen( $datafile, "r" ) or die( "File Error" );
$current = trim(fgets( $df ));
$goal = trim(fgets( $df ));
$height = trim(fgets( $df ));
$width = trim(fgets( $df ));
fclose( $df );
if ($current > $goal) {
$current = 100;
$percent= "100%!";
} else if ($current == "" || $current == "0") {
$percent = "0%";
} else {
$percent = round(($current/$goal)*100) . "%";
}
$im = @imagecreate($width,$height)
or die("Cannot Initialize new GD image stream");
$bg = ImageColorAllocate($im,200,200,200); // grey
$fg = ImageColorAllocate($im,255,0,0); //red
$text_color = imagecolorallocate($im, 0, 0, 0); //black
$text_color1 = imagecolorallocate($im, 255, 255, 0255); //white
$fill = $height-(($current/$goal)*$height);
imagefilledrectangle($im, 0, $fill, $width, $height, $fg);
$font = 3;
imagestring($im, $font, 2, 0, trim($goal), $text_color);
imagestring($im, 5, 5, $height-$percent*$height/200-8, $percent,
$text_color1);
imagestring($im, $font, 2, $height-$percent*$height/100,
trim($current), $text_color);
imagepng($im);
imagedestroy($im);
?>
I am able to access this script using a simple HTML file if I do it with a
direct <img src="goalgraph.php" />. But when I try to do so using PHP within
the HTML, using echo, it does not work. I tried renaming the file php and
adding the "AddType application/x-httpd-php .htm" to a .htaccess file, but
no joy. Here is what I have:
<html>
<body>
Goalgraph
<hr />
<?php
//echo '<img src="' . "goalgraph.php" . '" />' . "\n";
$datafile = "goalgraphdata.txt";
if( file_exists($datafile) ) {
echo "File Found\n";
$df = fopen( $datafile, "r" ) or die( "File Error" );
$current = trim(fgets( $df ));
$goal = trim(fgets( $df ));
$height = trim(fgets( $df ));
$width = trim(fgets( $df ));
fclose( $df );
echo '<img src="' . htmlspecialchars("goalgraph.php?cur=" .
urlencode($current) . "&goal=" . urlencode($goal) .
"&width=" . urlencode($width) . "&height=" . urlencode($height) ) . '"
alt="Help us achieve our goal"' . " /> \n";
}
else
echo "File not found\n";
?>
<hr />
<img src="goalgraph.php" />
</body>
</html>
It's been a long time since I have done anything with PHP or HTML for that
matter, so I'm quite rusty, and it may be something simple. Any help will be
most kindly appreciated.
Thanks!
Paul
[toc] | [next] | [standalone]
| From | Richard Yates <richard@yatesguitar.com> |
|---|---|
| Date | 2012-12-19 07:02 -0800 |
| Message-ID | <9ml3d8te6o6c4u2f17hov6o0cuvp2bg8c7@4ax.com> |
| In reply to | #7850 |
On Wed, 19 Dec 2012 07:30:35 -0500, "P E Schoen" <paul@peschoen.com> wrote: >I am able to access this script using a simple HTML file if I do it with a >direct <img src="goalgraph.php" />. But when I try to do so using PHP within >the HTML, using echo, it does not work. If your html script works, and you want to change it so that php is generating the html, then run the php that you have and look at the resulting page source to see how it campares with the html that works. Richard Yates
[toc] | [prev] | [next] | [standalone]
| From | "P E Schoen" <paul@peschoen.com> |
|---|---|
| Date | 2012-12-19 13:13 -0500 |
| Message-ID | <kat04s$k96$1@dont-email.me> |
| In reply to | #7851 |
"Richard Yates" wrote in message news:9ml3d8te6o6c4u2f17hov6o0cuvp2bg8c7@4ax.com... > On Wed, 19 Dec 2012 07:30:35 -0500, "P E Schoen" <paul@peschoen.com> > wrote: >> I am able to access this script using a simple HTML file if I do it with >> a >> direct <img src="goalgraph.php" />. But when I try to do so using PHP >> within the HTML, using echo, it does not work. > If your html script works, and you want to change it so that php is > generating the html, then run the php that you have and look at the > resulting page source to see how it campares with the html that works. I was using Notepad to edit the file, so it was in Windows format and not UNIX. I thought it was possible to save the file in UNIX format with Notepad, but the only formats other than ANSI are Unicode and UTF-8, neither of which work properly. D-oh! Thanks, Paul
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-12-19 15:05 -0500 |
| Message-ID | <kat6lp$vdt$2@dont-email.me> |
| In reply to | #7854 |
On 12/19/2012 1:13 PM, P E Schoen wrote: > "Richard Yates" wrote in message > news:9ml3d8te6o6c4u2f17hov6o0cuvp2bg8c7@4ax.com... > >> On Wed, 19 Dec 2012 07:30:35 -0500, "P E Schoen" <paul@peschoen.com> >> wrote: > >>> I am able to access this script using a simple HTML file if I do it >>> with a >>> direct <img src="goalgraph.php" />. But when I try to do so using PHP >>> within the HTML, using echo, it does not work. > >> If your html script works, and you want to change it so that php is >> generating the html, then run the php that you have and look at the >> resulting page source to see how it campares with the html that works. > > I was using Notepad to edit the file, so it was in Windows format and > not UNIX. I thought it was possible to save the file in UNIX format with > Notepad, but the only formats other than ANSI are Unicode and UTF-8, > neither of which work properly. > > D-oh! > > Thanks, > > Paul That should not make a difference. ANSI is fine. The FTP transfer should be text (not binary) mode, and will take care of the line end differences. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | "P E Schoen" <paul@peschoen.com> |
|---|---|
| Date | 2012-12-19 16:59 -0500 |
| Message-ID | <katdbh$d39$1@dont-email.me> |
| In reply to | #7857 |
"Jerry Stuckle" wrote in message news:kat6lp$vdt$2@dont-email.me... > That should not make a difference. ANSI is fine. The FTP transfer should > be text (not binary) mode, and will take care of the line end differences. But I am editing the files on my local machine Apache server, so FTP is not used. I'm using the evaluation version of perledit, but I think I should try one of the other editors designed for code, such as notepad++ as suggested by Luuk. Now that I can get the PHP to work, I want to add some more functionality to this. There are some widgets that are designed to handle contributions through PayPal and other services, but I wanted to make something simple that my friend can easily add to his forum: http://dogsnharmony.com/community/ What I have now can be handled by simply adding the line: <img src="goalgraph.php" alt="Help us get to our goal" /> The graph can be updated by manually uploading a new "goalgraphdata.txt" file with the amounts on an occasional basis, although it would be nice to see the graph update when the contribution is made. So I wanted to simulate this by having text controls where a member can enter an amount, and then click a "Contribute" button, and have the graph update accordingly. There could also be another text box showing the total contributions. But I'm not sure quite how to do this. As it is now set up, I would have to add the new quantity, as entered in the HTML page, to the URL parameters in the PHP code. Or I could just write the new values to the text file. But I'm not sure how to transfer the values in the HTML controls to PHP variables to be written to the file. I can't find any PHP functions that would provide a listbox or textbox where a user can enter data. Of course, I could echo an HTML input of type text, but I'm not sure if the value is visible to PHP, as it is with JavaScript. Maybe this requires JSON or an equivalent. Any ideas? Thanks, Paul
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-12-19 17:50 -0500 |
| Message-ID | <katgb5$vlv$1@dont-email.me> |
| In reply to | #7861 |
On 12/19/2012 4:59 PM, P E Schoen wrote: > "Jerry Stuckle" wrote in message news:kat6lp$vdt$2@dont-email.me... > >> That should not make a difference. ANSI is fine. The FTP transfer >> should be text (not binary) mode, and will take care of the line end >> differences. > > But I am editing the files on my local machine Apache server, so FTP is > not used. I'm using the evaluation version of perledit, but I think I > should try one of the other editors designed for code, such as notepad++ > as suggested by Luuk. > Then you should be using the same OS for Apache as you are for your editor, and EOL differences should not be a problem. > Now that I can get the PHP to work, I want to add some more > functionality to this. There are some widgets that are designed to > handle contributions through PayPal and other services, but I wanted to > make something simple that my friend can easily add to his forum: > http://dogsnharmony.com/community/ > > What I have now can be handled by simply adding the line: > <img src="goalgraph.php" alt="Help us get to our goal" /> > > The graph can be updated by manually uploading a new "goalgraphdata.txt" > file with the amounts on an occasional basis, although it would be nice > to see the graph update when the contribution is made. So I wanted to > simulate this by having text controls where a member can enter an > amount, and then click a "Contribute" button, and have the graph update > accordingly. There could also be another text box showing the total > contributions. > > But I'm not sure quite how to do this. As it is now set up, I would have > to add the new quantity, as entered in the HTML page, to the URL > parameters in the PHP code. Or I could just write the new values to the > text file. But I'm not sure how to transfer the values in the HTML > controls to PHP variables to be written to the file. > > I can't find any PHP functions that would provide a listbox or textbox > where a user can enter data. Of course, I could echo an HTML input of > type text, but I'm not sure if the value is visible to PHP, as it is > with JavaScript. Maybe this requires JSON or an equivalent. Any ideas? > > Thanks, > > Paul There are none. PHP runs on the server, not the client. It communicates with the client via HTTP. You need to send the appropriate HTML to the client and get the response back when the user submits the form. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Luuk <luuk@invalid.lan> |
|---|---|
| Date | 2012-12-19 21:23 +0100 |
| Message-ID | <rak9q9-obn.ln1@luuk.invalid.lan> |
| In reply to | #7854 |
On 19-12-2012 19:13, P E Schoen wrote: > I was using Notepad to edit the file, so it was in Windows format and > not UNIX. I thought it was possible to save the file in UNIX format with > Notepad, but the only formats other than ANSI are Unicode and UTF-8, > neither of which work properly. > a free editor like Notepad++ can do this for you http://notepad-plus-plus.org/
[toc] | [prev] | [next] | [standalone]
| From | "P E Schoen" <paul@peschoen.com> |
|---|---|
| Date | 2012-12-19 18:33 -0500 |
| Message-ID | <katisb$eqn$1@dont-email.me> |
| In reply to | #7858 |
"Luuk" wrote in message news:rak9q9-obn.ln1@luuk.invalid.lan... > a free editor like Notepad++ can do this for you > http://notepad-plus-plus.org/ I just downloaded and installed this. It seems to be very good. Thanks, Paul
[toc] | [prev] | [next] | [standalone]
| From | Richard Yates <richard@yatesguitar.com> |
|---|---|
| Date | 2012-12-19 17:24 -0800 |
| Message-ID | <d1q4d8pc62rndu1gqjat0sbsi28sb6org4@4ax.com> |
| In reply to | #7866 |
On Wed, 19 Dec 2012 18:33:26 -0500, "P E Schoen" <paul@peschoen.com> wrote: >"Luuk" wrote in message news:rak9q9-obn.ln1@luuk.invalid.lan... > >> a free editor like Notepad++ can do this for you >> http://notepad-plus-plus.org/ > >I just downloaded and installed this. It seems to be very good. The only drawback I ran into was that it was a real pain to edit the color schemes to something useful. Seems like most of the presets were light text on dark backgrounds. I wondered why there were not preset color schemes that duplicated the defaults of other, well-used editors.
[toc] | [prev] | [next] | [standalone]
| From | "Peter H. Coffin" <hellsop@ninehells.com> |
|---|---|
| Date | 2012-12-19 14:32 -0600 |
| Message-ID | <slrnkd493o.4ja.hellsop@nibelheim.ninehells.com> |
| In reply to | #7854 |
On Wed, 19 Dec 2012 13:13:43 -0500, P E Schoen wrote: > "Richard Yates" wrote in message > news:9ml3d8te6o6c4u2f17hov6o0cuvp2bg8c7@4ax.com... > >> On Wed, 19 Dec 2012 07:30:35 -0500, "P E Schoen" <paul@peschoen.com> >> wrote: > >>> I am able to access this script using a simple HTML file if I do it >>> with a direct <img src="goalgraph.php" />. But when I try to do so >>> using PHP within the HTML, using echo, it does not work. > >> If your html script works, and you want to change it so that php >> is generating the html, then run the php that you have and look at >> the resulting page source to see how it campares with the html that >> works. > > I was using Notepad to edit the file, so it was in Windows format and > not UNIX. I thought it was possible to save the file in UNIX format > with Notepad, but the only formats other than ANSI are Unicode and > UTF-8, neither of which work properly. Time for a new article. "Notepad Considered Harmful: or How I Learned to Stop Worrying and Love Vi". -- "... I've seen Sun monitors on fire off the side of the multimedia lab. I've seen NTU lights glitter in the dark near the Mail Gate. All these things will be lost in time, like the root partition last week. Time to die...". -- Peter Gutmann in the scary.devil.monastery
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-12-19 17:51 -0500 |
| Message-ID | <katgdk$vlv$2@dont-email.me> |
| In reply to | #7860 |
On 12/19/2012 3:32 PM, Peter H. Coffin wrote: > On Wed, 19 Dec 2012 13:13:43 -0500, P E Schoen wrote: > >> "Richard Yates" wrote in message >> news:9ml3d8te6o6c4u2f17hov6o0cuvp2bg8c7@4ax.com... >> >>> On Wed, 19 Dec 2012 07:30:35 -0500, "P E Schoen" <paul@peschoen.com> >>> wrote: >> >>>> I am able to access this script using a simple HTML file if I do it >>>> with a direct <img src="goalgraph.php" />. But when I try to do so >>>> using PHP within the HTML, using echo, it does not work. >> >>> If your html script works, and you want to change it so that php >>> is generating the html, then run the php that you have and look at >>> the resulting page source to see how it campares with the html that >>> works. >> >> I was using Notepad to edit the file, so it was in Windows format and >> not UNIX. I thought it was possible to save the file in UNIX format >> with Notepad, but the only formats other than ANSI are Unicode and >> UTF-8, neither of which work properly. > > Time for a new article. "Notepad Considered Harmful: or How I Learned to > Stop Worrying and Love Vi". > LOL, I like notepad for quick and dirty stuff, i.e. testing code snippits - it's small and fast. But for real work I prefer Crimson editor on Windows, and vim on Linux. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2012-12-19 16:04 +0000 |
| Message-ID | <kasoik$onu$1@news.albasani.net> |
| In reply to | #7850 |
On 19/12/12 12:30, P E Schoen wrote:
> I am able to access this script using a simple HTML file if I do it with
> a direct <img src="goalgraph.php" />. But when I try to do so using PHP
> within the HTML, using echo, it does not work. I tried renaming the file
> php and adding the "AddType application/x-httpd-php .htm" to a .htaccess
> file, but no joy. Here is what I have:
>
> <html>
> <body>
> Goalgraph
> <hr />
> <?php
> //echo '<img src="' . "goalgraph.php" . '" />' . "\n";
well that's plain wrong ..you have too much of a buggers muddle of quotes.
printf makes things easier..
try
printf ('<img src="%s" />\n', 'goalgraph.php');
>
> $datafile = "goalgraphdata.txt";
> if( file_exists($datafile) ) {
> echo "File Found\n";
> $df = fopen( $datafile, "r" ) or die( "File Error" );
> $current = trim(fgets( $df ));
> $goal = trim(fgets( $df ));
> $height = trim(fgets( $df ));
> $width = trim(fgets( $df ));
> fclose( $df );
>
> echo '<img src="' . htmlspecialchars("goalgraph.php?cur=" .
> urlencode($current) . "&goal=" . urlencode($goal) .
> "&width=" . urlencode($width) . "&height=" . urlencode($height) ) .
> '" alt="Help us achieve our goal"' . " /> \n";
> }
> else
> echo "File not found\n";
> ?>
> <hr />
> <img src="goalgraph.php" />
> </body>
>
> </html>
>
> It's been a long time since I have done anything with PHP or HTML for
> that matter, so I'm quite rusty, and it may be something simple. Any
> help will be most kindly appreciated.
>
> Thanks!
>
> Paul
--
Ineptocracy
(in-ep-toc’-ra-cy) – a system of government where the least capable to
lead are elected by the least capable of producing, and where the
members of society least likely to sustain themselves or succeed, are
rewarded with goods and services paid for by the confiscated wealth of a
diminishing number of producers.
[toc] | [prev] | [next] | [standalone]
| From | "P E Schoen" <paul@peschoen.com> |
|---|---|
| Date | 2012-12-19 13:23 -0500 |
| Message-ID | <kat0ni$oa5$1@dont-email.me> |
| In reply to | #7852 |
"The Natural Philosopher" wrote in message
news:kasoik$onu$1@news.albasani.net...
> On 19/12/12 12:30, P E Schoen wrote:
<html>
<body>
Goalgraph
<hr />
<?php
//echo '<img src="' . "goalgraph.php" . '" />' . "\n";
> well that's plain wrong ..you have too much of a buggers muddle of quotes.
> printf makes things easier..
> try
> printf ('<img src="%s" />\n', 'goalgraph.php');
Actually that mishmash and the other "img src" using variables were
"correct", ugly enough.
The problem was not using UNIX file format.
Thanks,
Paul
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web