php-general Digest 20 Aug 2005 09:49:57 -0000 Issue 3635

Topics (messages 220976 through 220998):

Re: Unique user?
        220976 by: Labunski

Document source code for PHP5
        220977 by: Markus Fischer

Automated data upload for customers
        220978 by: Brian Dunning
        220979 by: Jasper Bryant-Greene
        220980 by: Richard Lynch
        220981 by: Jasper Bryant-Greene
        220992 by: Richard Lynch

Re: PHP MySQL insert
        220982 by: Richard Lynch

Re: preg_match
        220983 by: Richard Lynch
        220984 by: Richard Lynch
        220985 by: Richard Lynch

Re: upload large files troubles
        220986 by: Richard Lynch
        220988 by: Jasper Bryant-Greene

php explained in sql
        220987 by: John Taylor-Johnston
        220990 by: Jasper Bryant-Greene

Re: php 5.04 register_globals aint acting right.
        220989 by: Richard Lynch

Re: Week Days
        220991 by: Richard Lynch
        220994 by: Robert Cummings
        220995 by: benc11.gmail.com
        220996 by: benc11.gmail.com

Hardware Detection
        220993 by: Saenal M
        220997 by: Burhan Khalid

Super globals ?
        220998 by: Wong HoWang

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:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Simply ad some info to the Cookies (including date and time). 

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

I'm currently using phpdoc.org to generated documentation of my code, but it doesn't seem to support PHP5. Interfaces are not recognized and function headers defined therein are parsed as public function.

Can someone recommend a documentation tool which supports the new PHP5 syntax?

thanks,
- markus

--- End Message ---
--- Begin Message --- I have a system where I'm trying to facilitate a process for customers to upload data to me (basically a list of people), and have it go into a database. I can give them certain parameters, like it has to be a CSV file, delimited in such a way, etc. but can't ask much more of them than that, since people are largely stupid. :)

And then there would be the usual multipart form upload where they select their file and send it up. I'd need to import it into MySQL.

Before I sit down and start coding this thing from scratch, does anyone know if there is something similar out there already that could give me a head start?

- Brian

--- End Message ---
--- Begin Message ---
Brian Dunning wrote:
I have a system where I'm trying to facilitate a process for customers to upload data to me (basically a list of people), and have it go into a database. I can give them certain parameters, like it has to be a CSV file, delimited in such a way, etc. but can't ask much more of them than that, since people are largely stupid. :)

For CSV, it's as simple as explode() the data by "\n" (perhaps strip out any "\r" before you start) and then explode() by ",". Depending on the software they're using, you might also need to remove any delimiters on each field of data, such as quote marks (").

If other file formats are possible as well as CSV, you might like to look at the PEAR "File Formats" packages[1].

And then there would be the usual multipart form upload where they select their file and send it up. I'd need to import it into MySQL.

Again, just receive the file data, do some checking to make sure it's of the expected type, run mysql_real_escape_string() on it, and insert it into a MySQL table.

You could use a PEAR package such as HTTP_Upload[2] to help with the uploading bit, and perhaps a database abstraction layer such as PEAR's DB package[3] for the MySQL bit.

Before I sit down and start coding this thing from scratch, does anyone know if there is something similar out there already that could give me a head start?

HTH

Jasper

[1] http://pear.php.net/packages.php?catpid=33&catname=File%20Formats
[2] http://pear.php.net/package/HTTP_Upload
[3] http://pear.php.net/package/DB

--- End Message ---
--- Begin Message ---
On Fri, August 19, 2005 3:47 pm, Jasper Bryant-Greene wrote:
> Brian Dunning wrote:
>> I have a system where I'm trying to facilitate a process for
>> customers
>> to upload data to me (basically a list of people), and have  it go
>> into
>> a database. I can give them certain parameters, like it  has to be a
>> CSV
>> file, delimited in such a way, etc. but can't ask  much more of them
>> than that, since people are largely stupid.  :)
>
> For CSV, it's as simple as explode() the data by "\n" (perhaps strip
> out
> any "\r" before you start) and then explode() by ",". Depending on the
> software they're using, you might also need to remove any delimiters
> on
> each field of data, such as quote marks (").

No, it's not that simple, as embedded commas can be inside of quotes,
and then quote quote is used for quotes inside of quotes.

Which is why PHP has a function for reading CSV files.
http://php.net/fgetcsv I believe.

> If other file formats are possible as well as CSV, you might like to
> look at the PEAR "File Formats" packages[1].

Now TAB delimited is generally easier than CSV as it IS as simple as
reading a line and explode() on "\t"

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
Richard Lynch wrote:
On Fri, August 19, 2005 3:47 pm, Jasper Bryant-Greene wrote:
For CSV, it's as simple as explode() the data by "\n" (perhaps strip
out
any "\r" before you start) and then explode() by ",". Depending on the
software they're using, you might also need to remove any delimiters
on
each field of data, such as quote marks (").

No, it's not that simple, as embedded commas can be inside of quotes,
and then quote quote is used for quotes inside of quotes.

Which is why PHP has a function for reading CSV files.
http://php.net/fgetcsv I believe.

Very good point. It can still be solved relatively simply with PHP's string and/or regex functions though, although that would be rather pointless as a function already exists. Thanks for pointing out the function, I hadn't seen it before.

If other file formats are possible as well as CSV, you might like to
look at the PEAR "File Formats" packages[1].

Now TAB delimited is generally easier than CSV as it IS as simple as
reading a line and explode() on "\t"

Unless of course the field is delimited with quotes and contains an embedded tab character? Just a guess, I haven't had any reason to use tab-delimited files before.

Jasper

--- End Message ---
--- Begin Message ---
On Fri, August 19, 2005 7:45 pm, Jasper Bryant-Greene wrote:
>>>If other file formats are possible as well as CSV, you might like to
>>>look at the PEAR "File Formats" packages[1].
>>
>> Now TAB delimited is generally easier than CSV as it IS as simple as
>> reading a line and explode() on "\t"
>
> Unless of course the field is delimited with quotes and contains an
> embedded tab character? Just a guess, I haven't had any reason to use
> tab-delimited files before.

tab-delimited does not allow tabs in data, nor newlines.

There is no escape character.

It follows the KISS principle.

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Fri, August 19, 2005 12:56 pm, areguera wrote:
>> could you suggest something about Latin characters and portability?.

As I understand it, or not, more likely, you want to configure your
MySQL server to use UTF-8, and your MySQL client to use UTF-8 and
pretty much everything to use UTF-8, and then you can convert your
data to UTF-8 and its gonna store it in a way that you'll be able to
convert back to Latin-1 or whatever you like.

At least, that's what Mark Matthews of MySQL A/B said in his talk
about this at our more recent Chicago MySQL User Group meeting.

You may want to take this question to the i18n PHP list, where people
who have actually done it hang out. :-)

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Fri, August 19, 2005 7:03 am, Matthew Weier O'Phinney wrote:
> * John Nichel <[EMAIL PROTECTED]> :
>> Richard Lynch wrote:
>> > On Thu, August 18, 2005 2:50 pm, Jon wrote:
>> > > preg_match_all("/Charges \s\s+ $total x (.+) /siU", $single,
>> > > $from_invoice);
>> >
>> > I would recommend using \\s instead of \s -- While \s doesn't have
>> any
>> > meaning in PHP strings, so PHP just figures you must have meant
>> \\s
>> <snip>
>>
>> But in perl type regex's, the \s is a space.  Without testing it, I
>> don't think \\s would match what the OP was looking for (I *think*

But Perl isn't going to *SEE* \\s !!!

PHP is going to *EAT* \\ and make \ out of it.

That's why \ is an escape character in PHP.

It's also an escape character in Perl/PCRE.

Some days I think PHP's escape character should have been | or
something, just so this topic wouldn't come up every damn month.

>> it
>> would match '\s').  However, I don't understand why the OP is
>> looking
>> for a space " ", followed by a space "\s", followed by multiple
>> spaces
>> "\s+"....a \s{1,} would have done all that just fine.
>
> But in double quotes, \ is seen as an escape, and could be interpreted
> differently. Probably the better way to do this would be:
>
> $pattern = '/Charges\s+' . $total . ' x ([^\s]*)/si';
> preg_match_all($pattern, $single, $from_invoice);

But in single quote \ is ALSO an escape, albeit for a smaller number
of characters -- 2, to be precise.

I don't care if you use single or double quotes, if you want PCRE to
get \s, then PHP should be using \\s inside of them.

PHP "eats" a \\ and spits out \ and then PCRE "sees" \s which is what
you want.

This is true for both single and double quotes.

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Fri, August 19, 2005 6:35 am, John Nichel wrote:
> Jon wrote:
>> preg_match_all("/Charges \s\s+ $total x (.+) /siU", $single,
>> $from_invoice);
>
> You'll probably need to assemble that expression first.  The regex may
> be seeing the dollar sign for your variable as an end of line
> delimiter.

Not a chance.

PHP is gonna splice $total into the string ages and ages before PCRE
sees it.

Okay, microseconds before, really, but that's ages in electron time. :-)

> $match = "/Charges\s{1,}" . $total . "\sx\s(.*)\s/siU";
> preg_match_all ( $match, $single, $from_invoice );

I still contend that $total has "/#" in it when it breaks.

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Fri, August 19, 2005 6:32 am, John Nichel wrote:
> Richard Lynch wrote:
>> On Thu, August 18, 2005 2:50 pm, Jon wrote:
>>
>>>preg_match_all("/Charges \s\s+ $total x (.+) /siU", $single,
>>>$from_invoice);
>>
>>
>> I would recommend using \\s instead of \s -- While \s doesn't have
>> any
>> meaning in PHP strings, so PHP just figures you must have meant \\s
> <snip>
>
> But in perl type regex's, the \s is a space.  Without testing it, I
> don't think \\s would match what the OP was looking for (I *think* it
> would match '\s').  However, I don't understand why the OP is looking
> for a space " ", followed by a space "\s", followed by multiple spaces
> "\s+"....a \s{1,} would have done all that just fine.

Actually, if he really needs a minimum of three spaces, as this string
indicates...

"\\s{3,}"

is probably the clearest representation.

Or possibly " {3,}"

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Fri, August 19, 2005 5:47 am, curipin wrote:

> I have apache2 + php5. I need to upload large files.  I found out,
> that
> file is uploaded always. But:
> - if the file is less than 167 MB all is OK, then I tryed larger files
> -
> from 191 MB up, files are uploaded, but php script, which handle the
> operation is "like" not executed. I always get blank (clear) page
> (f.e.
> echo "hello"; does not work!), so I can not let users know, that
> upload
> finished OK.
> Here is part of my php.ini file:
> max_execution_time = 70000
> max_input_time = 70000
> memory_limit = 16M
> post_max_size = 900M
> upload_max_filesize = 900M
> default_socket_timeout = 80000
> ....I think, these are all interested parts in this problem.

I believe httpd.conf has a RequestBodyLimit or somesuch which is also
a factor.

It's also possible that the *BROWSER* is going to time-out for an
action that takes too long, whether it's still pushing data or not.

I have a HUGE distrust of web browsers, so will go out on a limb and say:

Web browsers are not reliable transport mechanisms for upload of
monster files. Use FTP.

That might be wrong, but that's my story, and I'm sticking to it.

If somebody else wants to claim that uploading 200MB files in a
browser is a Good Idea, go right ahead.

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
Richard Lynch wrote:
I have a HUGE distrust of web browsers, so will go out on a limb and say:

Web browsers are not reliable transport mechanisms for upload of
monster files. Use FTP.

That might be wrong, but that's my story, and I'm sticking to it.

If somebody else wants to claim that uploading 200MB files in a
browser is a Good Idea, go right ahead.

I've definitely got to agree with you here. If you need to upload anything that size, or even half that size, I'd either use FTP, or develop something using raw sockets and a custom client app (if it needed to be super-user-friendly and your users didn't necessarily know how to use FTP).

Jasper

--- End Message ---
--- Begin Message --- In php, if I wanted to know if $mydata->email contained something, I would do this, right?
if ($mydata->email)
{}

How would I express this in SQL (MySQL)?

Thanks. Sorry to be off-topic, if I am,
John

--- End Message ---
--- Begin Message ---
John Taylor-Johnston wrote:
In php, if I wanted to know if $mydata->email contained something, I would do this, right?
if ($mydata->email)
{}

How would I express this in SQL (MySQL)?

That doesn't tell you if $mydata->email contains something. It tells you whether the value of $mydata->email, when cast to boolean, equals TRUE. If $mydata->email equaled zero or the string "0", it would still contain something, but that if statement would not get executed.

In MySQL, it would depend on the datatype. You could do any of the following, depending on what you actually want to do:

        colname<>''
        colname<>0
        colname IS NOT NULL

Or, if you're in MySQL >= 5.0.2 and are using true boolean values:

        colname IS TRUE

or, if you just want to check if it's TRUE or UNKNOWN:

        colname IS NOT FALSE


Jasper

--- End Message ---
--- Begin Message ---
On Fri, August 19, 2005 2:14 am, Jochem Maas wrote:
> true. I was just pointing out how easy it is to 'fake'
> register_globals
> personally all my code currently runs this on init - because I don't
> like reg.globals at all:
>
> function unRegisterGlobals()
> {
>      if (ini_get('register_globals')) {
>          $SGs = array($_SERVER, $_ENV, $_FILES, $_COOKIE, $_POST,
> $_GET);
>          if (isset($_SESSION)) { array_unshift($SGs, $_SESSION); }
>
>          foreach ($SGs as $sg) {
>              foreach ($superglobal as $k => $v) { unset($GLOBALS[ $k
> ]); }
>          }
>
>          ini_set('register_globals', false);
>      }
> }
>

Like, if you are doing this before anything else in your script, I
*THINK* you could just do:

$GLOBALS = array();

instead of all that looping and stuff.

I don't THINK there are any variables you're not nuking anyway...

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Thu, August 18, 2005 10:57 pm, [EMAIL PROTECTED] wrote:
> I am trying to add 3 (or a user-defined amount) week days to a certain
> date..
> An example is today 2005-08-18 then adding 3 week days to give me a
> date of
> 2005-08-23. I have tried searching online but cannot find an easy way
> of
> doing so.

Assuming you are willing to ignore holidays, which in most real-world
applications, you're not...

<?php
  $certain_date = '8/19/2005';
  $week_days = '...';
  list($m, $d, $y) = explode('/', $certain_date);
  $start = mktime(0, 0, 0, $m, $d, $y);
  //Every 5 days is a full week:
  $weeks = floor($week_days/5);
  $close = mktime(0, 0, 0, $m, $d + $weeks * 7, $y);
  $remainder = $week_days % 5;
  for ($added = 0, $day = 0; $added < $remainder; $day++){
    $dow = date('w', $close + $day*60*60*24); //Is it 'w' for 'day of
week'?
    if ($dow == 0 || $dow == 1){ //0|1 are Sun/Sat, right?
      $added++;
    }
  }
  $result = $close + $day * 60*60*24;
?>

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Sat, 2005-08-20 at 00:00, Richard Lynch wrote:
> On Thu, August 18, 2005 10:57 pm, [EMAIL PROTECTED] wrote:
> > I am trying to add 3 (or a user-defined amount) week days to a certain
> > date..
> > An example is today 2005-08-18 then adding 3 week days to give me a
> > date of
> > 2005-08-23. I have tried searching online but cannot find an easy way
> > of
> > doing so.
> 
> Assuming you are willing to ignore holidays, which in most real-world
> applications, you're not...
> 
> <?php
>   $certain_date = '8/19/2005';
>   $week_days = '...';
>   list($m, $d, $y) = explode('/', $certain_date);
>   $start = mktime(0, 0, 0, $m, $d, $y);
>   //Every 5 days is a full week:
>   $weeks = floor($week_days/5);
>   $close = mktime(0, 0, 0, $m, $d + $weeks * 7, $y);
>   $remainder = $week_days % 5;
>   for ($added = 0, $day = 0; $added < $remainder; $day++){
>     $dow = date('w', $close + $day*60*60*24); //Is it 'w' for 'day of
> week'?
>     if ($dow == 0 || $dow == 1){ //0|1 are Sun/Sat, right?

No, 6 is saturday :B   You know, I was looking for which fricking macro
expanded to a non locale based indicator for the day of the week
yesterday (ala the 'w' for date()). I guess my eyes were getting fuzzy
*grin*.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
Rob, 

I tried your code below, but it didn't work. I put the number of week days 
in $addWeekdays variable. Am I doing something wrong or is there an error in 
the code? Appreciate your help!

On 8/18/05, Robert Cummings <[EMAIL PROTECTED]> wrote:
> 
> On Fri, 2005-08-19 at 02:17, Robert Cummings wrote:
> > This doesn't work since the value can be user defined and thus may span
> > multiple weeks :) The following works but is dirty, I'm sure there's a
> > better solution using modulus operator and adding and subtracting and a
> > little voodoo... I'm just too lazy atm to think it up ;)
> 
> Ok so I felt like doing it :)
> 
> <?php
> 
> //
> // For every 5 days to add we wrap a week and are right back where we
> // started so...
> //
> 
> $addWeekdays = isset( $argv[1] ) ? $argv[1] : 0; // command line for fun
> $start = time();
> 
> $addWeeks = (int)($addWeekdays / 5);
> $addWeekDays = ($addWeekdays % 5);
> 
> $daySeconds = (24 * 60 * 60);
> 
> $final = $start + ($addWeeks * 7 * $daySeconds);
> while( $addWeekDays > 0 )
> {
> $final += $daySeconds;
> 
> $day = date( 'D', $final );
> if( $day != 'Sat' && $day != 'Sun' )
> {
> $addWeekDays--;
> }
> }
> 
> echo 'Start: '.date( 'Y-m-d (D)', $start )."\n";
> echo 'Final: '.date( 'Y-m-d (D)', $final )."\n";
> 
> 
> --
> .------------------------------------------------------------.
> | InterJinn Application Framework - http://www.interjinn.com |
> :------------------------------------------------------------:
> | An application and templating framework for PHP. Boasting |
> | a powerful, scalable system for accessing system services |
> | such as forms, properties, sessions, and caches. InterJinn |
> | also provides an extremely flexible architecture for |
> | creating re-usable components quickly and easily. |
> `------------------------------------------------------------'
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

--- End Message ---
--- Begin Message ---
Rob, 
 This code works great! Thank you for all of your help and everyone else who 
responded!

 On 8/18/05, Robert Cummings <[EMAIL PROTECTED]> wrote: 
> 
> On Fri, 2005-08-19 at 02:10, Jasper Bryant-Greene wrote:
> > [EMAIL PROTECTED] wrote:
> > > I am trying to add 3 (or a user-defined amount) week days to a certain 
> date..
> > > An example is today 2005-08-18 then adding 3 week days to give me a 
> date of
> > > 2005-08-23. I have tried searching online but cannot find an easy way 
> of
> > > doing so.
> >
> > $numDaysToAdd = 3;
> > $s = ($numDaysToAdd == 1) ? '' : 's';
> >
> > $dayInFuture = strtotime("+$numDaysToAdd day$s");
> > $dayName = date('l', $dayInFuture);
> > if($dayName == 'Saturday') {
> > $dayInFuture = strtotime("+2 days", $dayInFuture);
> > } else if($dayName == 'Sunday') {
> > $dayInFuture = strtotime("+1 day", $dayInFuture);
> > }
> >
> > Disclaimer: untested code.
> 
> This doesn't work since the value can be user defined and thus may span
> multiple weeks :) The following works but is dirty, I'm sure there's a
> better solution using modulus operator and adding and subtracting and a
> little voodoo... I'm just too lazy atm to think it up ;)
> 
> <?php
> 
> $weekdays = array
> (
> 'Mon' => true,
> 'Tue' => true,
> 'Wed' => true,
> 'Thu' => true,
> 'Fri' => true,
> );
> 
> $daySeconds = (60 * 60 * 24);
> 
> $start = time();
> $addWeekdays = 3;
> 
> $final = $start;
> while( $i < $addWeekdays )
> {
> $final += $daySeconds;
> echo date( 'D', $final )."\n";
> if( isset( $weekdays[date( 'D', $final )] ) )
> {
> $i++;
> }
> }
> 
> echo 'Start: '.date( 'Y-m-d (D)', $start )."\n";
> echo 'Final: '.date( 'Y-m-d (D)', $final )."\n";
> 
> Cheers,
> Rob.
> --
> .------------------------------------------------------------.
> | InterJinn Application Framework - http://www.interjinn.com |
> :------------------------------------------------------------:
> | An application and templating framework for PHP. Boasting |
> | a powerful, scalable system for accessing system services |
> | such as forms, properties, sessions, and caches. InterJinn |
> | also provides an extremely flexible architecture for |
> | creating re-usable components quickly and easily. |
> `------------------------------------------------------------'
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

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

Can we get information about hardware on client's PC. (e.g. hard disk, processor, keyboard, etc).? And How?
anyone knows? please reply back.

--- End Message ---
--- Begin Message ---
Saenal M wrote:
Hi,

Can we get information about hardware on client's PC. (e.g. hard disk, processor, keyboard, etc).? And How?
anyone knows? please reply back.

No, this is not possible with PHP.

--- End Message ---
--- Begin Message ---
Dear all,

Hello, I want to know that is there any way to create a super global in PHP?

Please help!
Thanks. 

--- End Message ---

Reply via email to