php-general Digest 22 Jun 2006 16:00:12 -0000 Issue 4200
Topics (messages 238500 through 238513):
Re: GD problems
238500 by: David Robley
Re: sort multidimension array
238501 by: Ford, Mike
detect user click "stop" button in browser
238502 by: weetat
238503 by: Andrei
templating
238504 by: Ryan A
238505 by: George Pitcher
238506 by: Jon Anderson
238507 by: Miles Thompson
238508 by: Dave Goodchild
238509 by: Joe Wollard
238511 by: Micky Hulse
Need help with PEAR Quickform
238510 by: Robert Graham
238512 by: Chris Boget
Equivelant to mysql_fetch_row for normal array
238513 by: Dave M G
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
php-general@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
Beauford wrote:
>
> There is something wonky with gd. I completely reinstalled Slackware
> today, including PHP, gd, and all the other stuff - and still nothing.
>
> I downloaded 5 separate captcha scripts and only got one to work. The code
> in all of them is very similar in that it creates a graphic with random
> letters and numbers.
>
> Here is the entire code from one that doesn't work.
>
> <?
>
> //---------------------------------------------------------------
> //This program is free software; you can redistribute it and/or
> //modify it under the terms of the GNU General Public License
> //as published by the Free Software Foundation; either version 2
> //of the License, or (at your option) any later version.
> //
> //This program is distributed in the hope that it will be useful,
> //but WITHOUT ANY WARRANTY; without even the implied warranty of
> //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> //GNU General Public License for more details.
> //
> //Meezerk's CAPTCHA - A Computer Assisted Program for Telling
> // Computers and Humans Apart
> //Copyright (C) 2004 Daniel Foster [EMAIL PROTECTED]
> //---------------------------------------------------------------
>
> //Select size of image
> $size_x = "75";
> $size_y = "25";
>
> //generate random string
> $code = mt_rand("100000","999999");
>
> //store captcha code in session vars
> session_start( );
> $_SESSION['captcha_code'] = $code;
>
> //create image to play with
> $image = imageCreate($size_x,$size_y);
>
>
> //add content to image
> //------------------------------------------------------
>
>
> //make background white - first colour allocated is background
> $background = imageColorAllocate($image,255,255,255);
>
>
>
> //select grey content number
> $text_number1 = mt_rand("0","150");
> $text_number2 = mt_rand("0","150");
> $text_number3 = mt_rand("0","150");
>
> //allocate colours
> $white = imageColorAllocate($image,255,255,255);
> $black = imageColorAllocate($image,0,0,0);
> $text =
> imageColorAllocate($image,$text_number1,$text_number2,$text_number3);
>
>
>
> //get number of dots to draw
> $total_dots = ($size_x * $size_y)/15;
>
> //draw many many dots that are the same colour as the text
> for($counter = 0; $counter < $total_dots; $counter++) {
> //get positions for dot
> $pos_x = mt_rand("0",$size_x);
> $pos_y = mt_rand("0",$size_y);
>
> //draw dot
> imageSetPixel($image,$pos_x,$pos_y,$text);
> };
>
>
>
> //draw border
> imageRectangle($image,0,0,$size_x-1,$size_y-1,$black);
>
>
>
> //get coordinates of position for string
> //on the font 5 size, each char is 15 pixels high by 9 pixels wide
> //with 6 digits at a width of 9, the code is 54 pixels wide
> $pos_x = bcmod($code,$size_x-60) +3;
> $pos_y = bcmod($code,$size_y-15);
>
> //draw random number
> imageString($image, 5, $pos_x, $pos_y, $code, $text);
>
>
> //------------------------------------------------------
> //end add content to image
>
>
> //send browser headers
> header("Content-Type: image/jpeg");
>
>
> //send image to browser
> echo imagejpeg($image);
>
>
> //destroy image
> imageDestroy($image);
>
>
> ?>
Well, you may not have the BCmath enabled, and this script will break if
bcmod isn't there, probably without you seeing an error message.
A tip for debugging image scripts - comment out the line like
header("Content-Type: image/jpeg");
and run the script again; if there is an error it will be displayed (error
settings permitting) whereas with the header in place, all you will get is
the broken image icon, most likely.
Cheers
--
David Robley
A life lived in fear is half a life lived.
Today is Pungenday, the 27th day of Confusion in the YOLD 3172.
--- End Message ---
--- Begin Message ---
On 22 June 2006 02:22, weetat wrote:
> Hi all,
>
> I have multi-arrays as shown below:
> I implemented usort() to sort the array by 'country' field
> in the array.
> However there some empty string value in the array and i setup my
> cmpcountry() function to sort array, however , some country
> empty string
> value are sort first .
>
> Any ideas what happen in the cmpcountry() function ?
>
> The result of sort array below is :
>
> Singapore
> Singapore
> Thailand
> ''
> Thailand
> ''
> ''
> Malaysia
> Phillipines
>
>
> function cmpcountry($a, $b)
> {
>
> $country1 = $a['country'];
> $country2 = $b['country'];
>
> if($country1 == ''){
> if($country1 < $country2){
> return 1;
> }
> }
>
> if($country2 == '') {
> if($country1 < $country2){
> return 1;
> }
> }
>
> return ($country1 < $country2) ? -1 : 1;
> }
I can't see what your additional if statements give you that a straight
comparison wouldn't. Under normal circumstances, '' will sort exactly where
you want it, so this is an ideal case for a straight strcmp:
function cmpcountry($a, $b)
{
return strcmp($a['country'], $b['country']);
}
If, however, what you're trying to do is send all blank entries to the end, you
only need the tests for empty string:
function cmpcountry($a, $b)
{
$country1 = $a['country'];
$country2 = $b['country'];
if($country1 == '') return 1;
if($country2 == '') return -1;
return strcmp($country1, $country2);
}
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
To view the terms under which this email is distributed, please go to
http://disclaimer.leedsmet.ac.uk/email.htm
--- End Message ---
--- Begin Message ---
Hi all,
Can we detected if user have clicked the "X" button in browser or
close browser ?
I have tested in my php program ,when i click "X" in IE6 , the
execution did not stop , it still running .
Any ways to stop the program execution when user click the "X" button
or close browser ?
Thanks
- weetat
--- End Message ---
--- Begin Message ---
Check int connection_aborted ( ) in the PHP manual
Andy
weetat wrote:
> Hi all,
>
> Can we detected if user have clicked the "X" button in browser or
> close browser ?
> I have tested in my php program ,when i click "X" in IE6 , the
> execution did not stop , it still running .
> Any ways to stop the program execution when user click the "X" button
> or close browser ?
>
> Thanks
> - weetat
>
--- End Message ---
--- Begin Message ---
Hi,
A pal of mine needed some help on his project, he is
using a "header" and "footer" file to "template" his
project... but its gotten a bit complicated as he has
a few dynamic parts in the header and footer files, so
I told him to go with a proper templating method of
templating the whole page rather than includ()ing the
top and bottom.
After having a better look at his scripts, I am just
not sure if something big (like SMARTY for instance)
would be good for him. He just needs maybe 5 template
pages, same pages, different color.
Searching google I see literally hundreds of
"templating solutions" can anyone recommend a simple
one or should I tell him to just use str_replace() for
tags like: {{menu_here}} {{header_here} etc?
Something like SMARTY would be like using a nuke to
kill a fly (IMHO) esp since this project will not
expand to anything much bigger or complicated.
Thanks!
Ryan
------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--- End Message ---
--- Begin Message ---
Ryan,
I would still recommend Smarty.
It can be as big as you like, but it can also be very simple to set up and
maintain. It has the features should your friend decide to expand his usage
in the future. If you opt now for something with limited features and later
decide to step beyond them, you'll be faced with making another major change
then.
Just my 2p worth.
George in Oxford
> -----Original Message-----
> From: Ryan A [mailto:[EMAIL PROTECTED]
> Sent: 22 June 2006 12:10 pm
> To: php php
> Subject: [PHP] templating
>
>
> Hi,
>
> A pal of mine needed some help on his project, he is
> using a "header" and "footer" file to "template" his
> project... but its gotten a bit complicated as he has
> a few dynamic parts in the header and footer files, so
> I told him to go with a proper templating method of
> templating the whole page rather than includ()ing the
> top and bottom.
>
> After having a better look at his scripts, I am just
> not sure if something big (like SMARTY for instance)
> would be good for him. He just needs maybe 5 template
> pages, same pages, different color.
>
> Searching google I see literally hundreds of
> "templating solutions" can anyone recommend a simple
> one or should I tell him to just use str_replace() for
> tags like: {{menu_here}} {{header_here} etc?
> Something like SMARTY would be like using a nuke to
> kill a fly (IMHO) esp since this project will not
> expand to anything much bigger or complicated.
>
> Thanks!
> Ryan
>
> ------
> - The faulty interface lies between the chair and the keyboard.
> - Creativity is great, but plagiarism is faster!
> - Smile, everyone loves a moron. :-)
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Ryan A wrote:
Hi,
A pal of mine needed some help on his project, he is
using a "header" and "footer" file to "template" his
project... but its gotten a bit complicated as he has
a few dynamic parts in the header and footer files, so
I told him to go with a proper templating method of
templating the whole page rather than includ()ing the
top and bottom.
This somewhat a "religious" issue for some, but my personal opinion is
that PHP is often very good at being a simple template system. Just
assign your variables beforehand, and display them with the <?= $var ?>
tag. (I do this with entire pages, split up into chunks for various
parts of content.)
I.e. template_head.php:
<?php
<html>
<head>
<title><?= $page_title ?>
<?php foreach ($css_files as $fn) { ?>
<style type="text/css">@import "<?= $fn ?>";</style>
<?php } /* end foreach ($js_files) */ ?>
</head>
<body>
?>
etc...
Then your page would look like:
<?php
/* Assign some variables */
...
include('template_head.php');
/* A little workhorse code, assign some more variables */
...
include('template_content1.php');
/* Assign even more variables */
...
include('template_foot.php');
After having a better look at his scripts, I am just
not sure if something big (like SMARTY for instance)
would be good for him. He just needs maybe 5 template
pages, same pages, different color.
Smarty is also excellent. (I still prefer pure PHP though. :-)
Searching google I see literally hundreds of
"templating solutions" can anyone recommend a simple
one or should I tell him to just use str_replace() for
tags like: {{menu_here}} {{header_here} etc?
Something like SMARTY would be like using a nuke to
kill a fly (IMHO) esp since this project will not
expand to anything much bigger or complicated.
Why kill performance when you don't have to?
jon
--- End Message ---
--- Begin Message ---
At 08:10 AM 6/22/2006, Ryan A wrote:
Hi,
A pal of mine needed some help on his project, he is
using a "header" and "footer" file to "template" his
project... but its gotten a bit complicated as he has
a few dynamic parts in the header and footer files, so
I told him to go with a proper templating method of
templating the whole page rather than includ()ing the
top and bottom.
After having a better look at his scripts, I am just
not sure if something big (like SMARTY for instance)
would be good for him. He just needs maybe 5 template
pages, same pages, different color.
Searching google I see literally hundreds of
"templating solutions" can anyone recommend a simple
one or should I tell him to just use str_replace() for
tags like: {{menu_here}} {{header_here} etc?
Something like SMARTY would be like using a nuke to
kill a fly (IMHO) esp since this project will not
expand to anything much bigger or complicated.
Thanks!
Ryan
Ryan,
Don't forget, PHP itself is a templating language. Just do a standard page,
with includes for headers and footers, menus, and content.
If he wants to change colour, then load a different stylesheet for a given
page or content section.
This way he can use the tool that's right in front of him, he's not adding
another layer, he does not have to learn another "language" - the template
system written in PHP, and he hones his PHP skills.
Whew! Hope this is helpful.
Regards - Miles
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.1.394 / Virus Database: 268.9.2/372 - Release Date: 6/21/2006
--- End Message ---
--- Begin Message ---
On 22/06/06, Miles Thompson <[EMAIL PROTECTED]> wrote:
At 08:10 AM 6/22/2006, Ryan A wrote:
>Hi,
>
>A pal of mine needed some help on his project, he is
>using a "header" and "footer" file to "template" his
>project... but its gotten a bit complicated as he has
>a few dynamic parts in the header and footer files, so
>I told him to go with a proper templating method of
>templating the whole page rather than includ()ing the
>top and bottom.
>
>After having a better look at his scripts, I am just
>not sure if something big (like SMARTY for instance)
>would be good for him. He just needs maybe 5 template
>pages, same pages, different color.
>
>Searching google I see literally hundreds of
>"templating solutions" can anyone recommend a simple
>one or should I tell him to just use str_replace() for
>tags like: {{menu_here}} {{header_here} etc?
>Something like SMARTY would be like using a nuke to
>kill a fly (IMHO) esp since this project will not
>expand to anything much bigger or complicated.
>
>Thanks!
>Ryan
I agree with Ryan - here is an example of a simple template I am using on a project at the moment. Stylesheets are used to control look and feel and the body tag is assigned a class so that different pages can use different layout elements. Hope this helps.
--
http://www.web-buddha.co.uk
http://www.projectkarma.co.uk
--- End Message ---
--- Begin Message ---
IMHO I would go with Smarty as it has excellent documentation and
would fit almost anything that the project would require. I also
think it would be a cleaner way of templating than using str_replace
() over and over again. For what it's worth, I use Smarty on almost
all of my projects, large and small. I find that once you learn it
you can use it to develop new sites rather quickly.
...and it's not like using a nuke to kill a fly - Smarty only loads
the files it needs as it needs them instead of loading everything -
so it's quite fast really.
- Joe
On Jun 22, 2006, at 7:10 AM, Ryan A wrote:
Hi,
A pal of mine needed some help on his project, he is
using a "header" and "footer" file to "template" his
project... but its gotten a bit complicated as he has
a few dynamic parts in the header and footer files, so
I told him to go with a proper templating method of
templating the whole page rather than includ()ing the
top and bottom.
After having a better look at his scripts, I am just
not sure if something big (like SMARTY for instance)
would be good for him. He just needs maybe 5 template
pages, same pages, different color.
Searching google I see literally hundreds of
"templating solutions" can anyone recommend a simple
one or should I tell him to just use str_replace() for
tags like: {{menu_here}} {{header_here} etc?
Something like SMARTY would be like using a nuke to
kill a fly (IMHO) esp since this project will not
expand to anything much bigger or complicated.
Thanks!
Ryan
------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Miles Thompson wrote:
Don't forget, PHP itself is a templating language. Just do a standard
page, with includes for headers and footers, menus, and content.
If he wants to change colour, then load a different stylesheet for a
given page or content section.
This way he can use the tool that's right in front of him, he's not
adding another layer, he does not have to learn another "language" - the
template system written in PHP, and he hones his PHP skills.
I agree. I think this would be the best solution for a simple site. Good
point about honing PHP skillz.
As far as a CMS goes, textpattern is pretty dope. Simple to setup, free,
and it has a kick-butt template system.
Gl,
Cheers,
Micky
--- End Message ---
--- Begin Message ---
Good day
I am busy working on a form using QuickForm.
I would like to make use of a confirmation page where the user must
eitheir select to change the details or continue. Does anyone know how
to achieve this?
Regards
Robert
--- End Message ---
--- Begin Message ---
> I am busy working on a form using QuickForm.
> I would like to make use of a confirmation page
> where the user must eitheir select to change the
> details or continue. Does anyone know how to
> achieve this?
On POST, you could redisplay the form in a "Frozen"
state. If the form is frozen, you display a separate
set of submit buttons and in checking to see if those
new buttons were clicked do you actually process the
form normally (access data store, etc).
This is just one of the many ways you can go about
achieving the same results.
thnx,
Chris
--- End Message ---
--- Begin Message ---
PHP List,
Very frequently I use mysql_fetch_row in a while statement to
while($variable = mysql_fetch_row($mysqlResult)){
echo $variable[text1];
echo $variable[text2];
}
Pretty standard.
But what do I do when I want to do the same kind of while loop not with
a MySQL result, but with just a regular array?
while (variable = ????($array)){
echo $variable[text1];
echo $variable[text2];
}
I've been up and down the manual, and looked at foreach statements and
functions like each(), but I can't seem to zero in on what I need.
Can anyone let me know what it is I'm missing?
Thank you for any advice.
--
Dave M G
--- End Message ---