php-general Digest 13 Jun 2009 09:17:24 -0000 Issue 6173

Topics (messages 293992 through 294000):

Re: opendir() Question
        293992 by: Andrew Ballard
        293996 by: Parham Doustdar

Re: Form handling
        293993 by: Dajve Green

Re: Dynamic Titles
        293994 by: David Robley
        293995 by: Austin Caudill

Doubt on why some syntaxis is not used for PHP
        293997 by: Manuel Aude

about locale settings
        293998 by: Per Jessen

Periodic Actions in PHP?
        293999 by: Parham Doustdar
        294000 by: Richard Heyes

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
2009/6/12 Parham Doustdar <parha...@gmail.com>:
> Hi there,
> I need to create a PHP script that will connect to an  FTP, get a listing of 
> files/directories from it, and displays them in a table. Now, there is only 
> one problem here.
> I tried connecting with opendir(), like this:
> opendir("ftp://...";);
> but it seems it doesn't work with FTP. Now, is there another thing I could 
> use for the same effect?
> Thanks!
> --
> ---
> Contact info:
> Skype: parham-d
> MSN: fire_lizard16 at hotmail dot com
> email: parham90 at GMail dot com

RTM http://www.php.net/ftp

Andrew

--- End Message ---
--- Begin Message ---
Hello there Andrew,
Thank you very much for your help. I didn't know such an extention existed. 
:)

-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com
"Andrew Ballard" <aball...@gmail.com> wrote in message 
news:b6023aa40906121312m47034863k9c502e07d66c4...@mail.gmail.com...
2009/6/12 Parham Doustdar <parha...@gmail.com>:
> Hi there,
> I need to create a PHP script that will connect to an FTP, get a listing 
> of files/directories from it, and displays them in a table. Now, there is 
> only one problem here.
> I tried connecting with opendir(), like this:
> opendir("ftp://...";);
> but it seems it doesn't work with FTP. Now, is there another thing I could 
> use for the same effect?
> Thanks!
> --
> ---
> Contact info:
> Skype: parham-d
> MSN: fire_lizard16 at hotmail dot com
> email: parham90 at GMail dot com

RTM http://www.php.net/ftp

Andrew 



--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Manuel Lemos [mailto:mle...@acm.org]
> Sent: 11 June 2009 07:21
> To: Eddie Drapkin
> Cc: PHP General Mailing List
> Subject: [PHP] Re: Form handling
> 
> Hello,
> 
> on 06/10/2009 03:10 PM Eddie Drapkin said the following:
> > I've been charged with writing a class that handles forms, once they've
> been
> > POSTed to.  The idea of the class is to handle the most common use-cases
> of
> > POST forms, and any special functionality can be handled with a child
> class
> > at a later date, but for our uses, we're going to have mostly pretty
> typical
> > POST forms.  Follows is the list of cases I've determined that are the
> most
> > common, can anyone think of any that are omitted or that are never going
> to
> > be used?
> >
> > class form_handler {
> >     public /* bool */ function setRequiredFields(array $fields); //takes
> a
> > simple array that corresponds to a $_POST key, verifying that there is
> data
> > on required fields but not for optional fields, returns true or false on
> > error
> >     public /* bool */ function setRequiredFieldTypes(array $fieldTypes);
> > //array of field names => type a la ('username' => array(regex,
> > '/a-zA-Z0-9\-_/'))
> >                 //or 'phone_number' => (array('int', 'min_len' => 7,
> > 'max_len' => 10)) etc, the exact spec is obviously nowhere near done but
> > will probably just wrap a lot of filter_ functions, returns true or
> false on
> > error
> >     public /* string */ function validateAndCaptureError(); //returns
> error
> > or empty string
> >     public /* void */ function validateAndForwardTo($page); //forwards
> to
> > page on error, or not
> > }
> >
> > each of the globule setters will have a corresponding appendRequired...
> > method, so as not to require handling enormous data structures for
> > conditional form building.
> > ♦
> > As you can see, the class looks pretty barren, but I can't think of any
> more
> > functionality than would be required, although I am kickign the idea
> around
> > of having very specific validation type methods ie.
> > form_handler::requireInt($field, array $options) or
> > form_handler::requireRegex($field, $regex), etc.
> >
> > Thoughts?
> 
> You may want consider not reinventing the wheel.
> 
> I use this popular forms generation and validation class since about 10
> years now. It can deal with pretty much all you need now and probably
> later.
> 
> http://www.phpclasses.org/formsgeneration
> 
> Here are some live examples of the class and its plug-ins.
> 
> http://www.meta-language.net/forms-examples.html
> 
> --
> 
> Regards,
> Manuel Lemos

Whilst Manuel's Forms Generation class / Zend Form et al are certainly quick 
and easy to integrate, if this is an in-house project, I don't see a problem 
with rolling your own Forms class designed to simply automate some of the 
common functionality your developers use. In a lot of cases, out-of-the-box 
classes come with bloat while being all things to all men, which is not a bad 
thing, per se, but needs to be weighed up when selecting a methodology.

To answer your original question, though, our in-house framework has a base 
Form class, which is extended through child classes, as well as a base input 
class, which is extended with child classes such as TextInput, SelectInput etc. 
This allows each input to have its individual validate() methods, as well as 
creating a wrapper Form::validate() method which loops through the 
Input::validate() methods.

Example

$Form           = new Form;
$Form->fields['text']   = new TextInput;
$Form->fields['select'] = new SelectInput;
$Form->fields['select']->options        = array('foo' => 'bar', 'wom' => 'bat');

With regard your setRequiredFields(), we use an Input::$mandatory property, 
which the Input::validate() method checks.
The setRequiredFieldTypes() is dealt with by the actual File class.
I would certainly separate out the required validation as mentioned with 
requireInt/Regex methods, which would allow combining of required conditions. 
We use a $validation bitwise property in the Input class combined with class 
constants, as well as minlength / maxlength properties for text / password 
fields.

Other things to consider

- Some method of storing user messages during validation which can be output 
later.

- Creating an output method for the fields. Repopulating the fields with 
submitted values, using CSS to highlight missing or invalid fields or creating 
"custom" fields (such as a date input with a calendar / made up of Y/M/D select 
inputs) can lead to a mess if you are hardcoding the output. 
For example:

$Form->fields['text']->add_css_class('missing_mandatory');
$Form->fields['text']->set_value('Foo');
$Form->fields['text']->output();

Something further to consider would be to have a $value property and use 
__set() overloading 
(http://us3.php.net/manual/en/language.oop5.overloading.php) to validate
Eg 
$Form->fields['select']->value = 'foo'; // Sets value to foo
$Form->fields['select']->value = 'No such option'; // Does not set

- A method / property to check whether the form has been submitted.
If you have a Form::id property, you can pass this through in a hidden field 
and create a method which checks for the presence of this in the $_POST array.
Example

class Form {
  public $id;
  public $form_id_key = 'my_form_id';

  public /* bool */ function has_been_submitted() {
    $submitted = false;
    
    if (array_key_exists($this->form_id_key,$_POST) &&
        $_POST[$this->form_id_key] == $this->id) {
      $submitted = true;
    }
    
    return $submitted;
  }
}

$Form->id = 'myform';
if ($Form->has_been_submitted()) {
  // Process the form
}

[snip]

<form method='post' action=''>
  <input  type = 'hidden' 
          name = '<?php echo $Form->form_id_key ?>' 
          value= '<?php echo $Form->id ?>' />
</form>

It would be worth thinking about how to handle cases where a Form id is null 
when checking for submission.


Finally, if the class starts out looking barren, that's not a problem - there's 
always room to expand if more functionality is needed. Filling a class with 
functionality you might need, without where and when you'll need it, or how you 
expect to use it is a Bad Thing.


Apologies all for the essay, but hopefully it's of some use.
Dajve

----------------------------------------------------------------------------
for (thoughts, ramblings && doodles) {
  goto http://dajve.co.uk ;
}



--- End Message ---
--- Begin Message ---
On Sat, 13 Jun 2009, you wrote:
> Well, im no longer getting any errors now, but its still not working.
> You can see it here: http://www.newtuts.com. When you go there, it
> should say "Photoshop tutorials, Flash tutorials . . .". This should be
> the default page. When you click on "Support", the title should become
> "Newtuts Help". But instead, it just says "echo $title". Any more
> ideas?
>
>
>
> Austin Caudill
>
> --- On Fri, 6/12/09, David Robley <robl...@aapt.net.au> wrote:
>
>
> From: David Robley <robl...@aapt.net.au>
> Subject: [PHP] Re: Dynamic Titles
> To: php-gene...@lists.php.net
> Date: Friday, June 12, 2009, 3:34 AM
>
> Austin Caudill wrote:
> > Hello, im trying to make the CMS system im using more SEO friendly by
> > giving each page it's own title. Right now, the system assigns all
> > pages the same general title. I would like to use PHP to discertain
> > which page is being viewed and in turn, which title should be used.
> >
> > I have put in the title tags the variable "$title". As for the PHP im
> > using, I scripted the following:
> >
> > $url = "http://'.$_SERVER['SERVER_NAME']''.$_SERVER['REQUEST_URI']'";
> > switch ( $url )
> > {
> > default:
> > $title = "Photoshop tutorials, Flash tutorials, and more! Newtuts
> > Tutorial Search"; break;
> >
> > case "$config[HTTP_SERVER]help.php" :
> > $title = "Newtuts Help";
> > break;
> > }
> >
> > Right now, im getting this error:
> > Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,
> > expecting T_STRING or T_VARIABLE or T_NUM_STRING in
> > /home/a7201901/public_html/includes/classes/tutorial.php on line 803
> >
> > Can someone please help me with this?
> >
> >
> >
> > Thanks!
>
> I'm guessing that line 803 is
>
> $url = "http://'.$_SERVER['SERVER_NAME']''.$_SERVER['REQUEST_URI']'";
>
> which is full of mismatched quotes :-) Try any of
>
> $url = "http://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";
> $url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
> $url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
>
> Cheers

Forwarding to the list for the benefit of others.

As you haven't shown the code that is supposed to produce the title, we're 
back to guessing again. Looking at the source of your Support page, I see 
the the Title tags are empty.

If you are seeing echo $title is it possible you forgot to use php tags 
around the php code?




Cheers
-- 
David Robley

"I haven't had any tooth decay yet," said Tom precariously.
Today is Prickle-Prickle, the 18th day of Confusion in the YOLD 3175. 

--- End Message ---
--- Begin Message ---
Yes, I corrected this problem. Now, the URL of each page is being displayed as 
the title. We are making progress! Now I just need to figure out why the URLs 
are shown as the title, and not whaty I want to be shown.



Austin Caudill

--- On Fri, 6/12/09, David Robley <da...@robley.net.au> wrote:


From: David Robley <da...@robley.net.au>
Subject: Re: [PHP] Re: Dynamic Titles
To: php-gene...@lists.php.net
Date: Friday, June 12, 2009, 9:29 PM


On Sat, 13 Jun 2009, you wrote:
> Well, im no longer getting any errors now, but its still not working.
> You can see it here: http://www.newtuts.com. When you go there, it
> should say "Photoshop tutorials, Flash tutorials . . .". This should be
> the default page. When you click on "Support", the title should become
> "Newtuts Help". But instead, it just says "echo $title". Any more
> ideas?
>
>
>
> Austin Caudill
>
> --- On Fri, 6/12/09, David Robley <robl...@aapt.net.au> wrote:
>
>
> From: David Robley <robl...@aapt.net.au>
> Subject: [PHP] Re: Dynamic Titles
> To: php-gene...@lists.php.net
> Date: Friday, June 12, 2009, 3:34 AM
>
> Austin Caudill wrote:
> > Hello, im trying to make the CMS system im using more SEO friendly by
> > giving each page it's own title. Right now, the system assigns all
> > pages the same general title. I would like to use PHP to discertain
> > which page is being viewed and in turn, which title should be used.
> >
> > I have put in the title tags the variable "$title". As for the PHP im
> > using, I scripted the following:
> >
> > $url = "http://'.$_SERVER['SERVER_NAME']''.$_SERVER['REQUEST_URI']'";
> > switch ( $url )
> > {
> > default:
> > $title = "Photoshop tutorials, Flash tutorials, and more! Newtuts
> > Tutorial Search"; break;
> >
> > case "$config[HTTP_SERVER]help.php" :
> > $title = "Newtuts Help";
> > break;
> > }
> >
> > Right now, im getting this error:
> > Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,
> > expecting T_STRING or T_VARIABLE or T_NUM_STRING in
> > /home/a7201901/public_html/includes/classes/tutorial.php on line 803
> >
> > Can someone please help me with this?
> >
> >
> >
> > Thanks!
>
> I'm guessing that line 803 is
>
> $url = "http://'.$_SERVER['SERVER_NAME']''.$_SERVER['REQUEST_URI']'";
>
> which is full of mismatched quotes :-) Try any of
>
> $url = "http://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";
> $url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
> $url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
>
> Cheers

Forwarding to the list for the benefit of others.

As you haven't shown the code that is supposed to produce the title, we're 
back to guessing again. Looking at the source of your Support page, I see 
the the Title tags are empty.

If you are seeing echo $title is it possible you forgot to use php tags 
around the php code?




Cheers
-- 
David Robley

"I haven't had any tooth decay yet," said Tom precariously.
Today is Prickle-Prickle, the 18th day of Confusion in the YOLD 3175. 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




      

--- End Message ---
--- Begin Message ---
I'm gonna guess that there might be some syntaxis problems or something,
since I would guess the following make sense to the PHP language.

Arrays: Since the + operator already gives the union of two arrays, why
isn't the - operator for differences and | for intersections? I would find
those to be rather natural and actually easy to implement.

Classes: I was also wondering why the static methods of a class use the ::
syntaxis. After all, I don't see what's the problem with also using -> for
static calls. Just by adding MyClass->staticMethod(), the whole problem of
namespaces and :: as separator would seem to be made a bit easier.

Just some questions =) I'm not here to say that things are wrong, just
wondering why they weren't thought to be the other way. Again, there might
be some syntaxis problem with the parser that I haven't thought so far.

Regards, Mamsaac

--- End Message ---
--- Begin Message ---
When I've set LC_ALL before calling php, why do I need to call
setlocale() in the script too:

LC_ALL=de_DE.utf8 php -r "print strftime('%B');"
June

LC_ALL=de_DE.utf8 php -r "setlocale(LC_ALL,''); print strftime('%B');"
Juni

What am I missing here?  I have no problem with the setlocale(LC_ALL,'')
call, but I'd like to understand why I need it.


-- 
Per Jessen, Zürich (16.1°C)


--- End Message ---
--- Begin Message ---
Hi there,
I'm going to create a small chat script with PHP. The messages you want others 
to see will be added to a flat file (I.E. TXT file), and read and displayed by 
PHP. However, I want this reading and displaying to be periodic. This means 
that I want PHP to check the file for new lines every,say, fifteen seconds. How 
may I do that? I have been unable to find any function that acts like a timer.
Thanks!
-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com

--- End Message ---
--- Begin Message ---
Hi,

> I'm going to create a small chat script with PHP. The messages you want 
> others to see
> will be added to a flat file (I.E. TXT file), and read and displayed by PHP. 
> However, I want
> this reading and displaying to be periodic. This means that I want PHP to 
> check the file for
> new lines every,say, fifteen seconds. How may I do that? I have been unable 
> to find any
> function that acts like a timer.

If you're on Unix then look into using cron. Type the following at the
command prompt to get info on cron:

man 5 crontab

Cron tasks can be scheduled at most once per minute. And if you're
using Windows then I believe the equivalent would be task scheduler,
but I've no idea how you would go about using it.

-- 
Richard Heyes
HTML5 graphing: RGraph (www.rgraph.net - updated 6th June)
PHP mail: RMail (www.phpguru.org/rmail)
PHP datagrid: RGrid (www.phpguru.org/rgrid)
PHP Template: RTemplate (www.phpguru.org/rtemplate)
PHP SMTP: http://www.phpguru.org/smtp

--- End Message ---

Reply via email to