php-general Digest 23 Jun 2002 23:59:53 -0000 Issue 1423

Topics (messages 103453 through 103505):

Insert an array into MySQL
        103453 by: Rob Packer
        103455 by: John Holmes
        103458 by: Rob Packer
        103459 by: Rob Packer
        103482 by: Rob Packer

Re: PHP 4.2
        103454 by: John Holmes
        103456 by: Pekka Saarinen
        103457 by: Justin French

Profiling
        103460 by: James Drabb
        103461 by: Justin French

Re: getaddrinfo failed
        103462 by: Pag

Whos online at the moment in PHP
        103463 by: Pag
        103466 by: Justin French
        103471 by: Chris Shiflett
        103491 by: Uros Gruber

output_buffering
        103464 by: James Drabb
        103468 by: Mark Charette

Problem with Apache2/PHP4.2.1
        103465 by: Simon Grabowski

Re: Error(Newbie)
        103467 by: Chris Shiflett
        103490 by: John Holmes

Re: Nested Menu Help
        103469 by: Lowell Allen

Re: netscape 4.x problem
        103470 by: Chris Shiflett

Remote cgi script function
        103472 by: Haddad Said
        103489 by: John Holmes

is there a way to track downloads
        103473 by: Kevin J
        103474 by: Duncan Hill
        103475 by: Kevin J
        103476 by: Julie Meloni
        103477 by: Kevin J
        103478 by: Duncan Hill
        103505 by: Henry

about file permissions + cuteftp
        103479 by: Adrian Murphy

Re: is there a function like javascript's window.open in PHP
        103480 by: Mark Charette
        103493 by: Burak Delice

Smarty compared to Roadsend?
        103481 by: Francisco Reyes

Re: Cc / Bcc don't work on win2k but on linux???
        103483 by: Christoph Grottolo

Formatting phone numbers
        103484 by: Corinne Shea
        103486 by: S.P. Telgenhof Oude Koehorst
        103487 by: Paul Roberts
        103497 by: Chris Shiflett

JPGraph errors
        103485 by: Christopher J. Crane

Re: Shot in the dark
        103488 by: Numero 6

How to put a "new line" character with  fputs($birthday_file, $content);
        103492 by: Alfredo
        103494 by: Duncan Hill
        103495 by: Mark Heintz PHP Mailing Lists
        103500 by: hugh danaher

php or mysql db update
        103496 by: Steven Dowd

Is this a BUG?
        103498 by: César Aracena
        103502 by: CC Zona
        103504 by: Andrew Brampton

retaining keys in array_splice
        103499 by: Austin W. Marshall

solution
        103501 by: Austin W. Marshall

php install in win32
        103503 by: Septic Flesh

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 ---
Hi, I've seen a few post for this same thing but I can't seem to get it
working. What I'm doing is taking a form with check boxes and putting them
into an array. Then I'm attempting to INSERT them into the db, one checkbox
value per row.

Okay,  well I've tries 2 ways that I think should work and they only insert
the first value. They both produce this error "Duplicate entry '0' for key
1" (which I don't understand) Anyway here is the code I'm trying...

(I'm not trying to use both blocks of code, just one or the other)

// First code
while(list($key,$value)=each($pagetype)){
//echo $value."<br>";//test
$links="INSERT INTO $username_links (links) VALUES ('$value')";
$insert=mysql_query($links,$connection);

}

// Second code attempt
$number=count($pagetype);
for($a=0;$a<$number;$a++){
$links="INSERT INTO $username_links (links) VALUES ('$pagetype[$a]')";
$insert=mysql_query($links) or die(mysql_error());
//echo $pagetype[$a];//test
}




Thanks in advance...Robert


--- End Message ---
--- Begin Message ---
Your second method should work, but it's dependent on what your form
looks like and how your table was created. You obviously have a key set
for this column and you're trying to insert the same value twice, which
makes an error.

Show us what your form looks like, not the whole thing, just for the
checkboxes. Also, what does your CREATE TABLE look like for the table
your trying to insert this data into?

---John Holmes...

> -----Original Message-----
> From: Rob Packer [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, June 23, 2002 7:50 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Insert an array into MySQL
> 
> Hi, I've seen a few post for this same thing but I can't seem to get
it
> working. What I'm doing is taking a form with check boxes and putting
them
> into an array. Then I'm attempting to INSERT them into the db, one
> checkbox
> value per row.
> 
> Okay,  well I've tries 2 ways that I think should work and they only
> insert
> the first value. They both produce this error "Duplicate entry '0' for
key
> 1" (which I don't understand) Anyway here is the code I'm trying...
> 
> (I'm not trying to use both blocks of code, just one or the other)
> 
> // First code
> while(list($key,$value)=each($pagetype)){
> //echo $value."<br>";//test
> $links="INSERT INTO $username_links (links) VALUES ('$value')";
> $insert=mysql_query($links,$connection);
> 
> }
> 
> // Second code attempt
> $number=count($pagetype);
> for($a=0;$a<$number;$a++){
> $links="INSERT INTO $username_links (links) VALUES ('$pagetype[$a]')";
> $insert=mysql_query($links) or die(mysql_error());
> //echo $pagetype[$a];//test
> }
> 
> 
> 
> 
> Thanks in advance...Robert
> 
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---

"John Holmes" <[EMAIL PROTECTED]> wrote in message
001201c21ab5$0df073a0$b402a8c0@mango">news:001201c21ab5$0df073a0$b402a8c0@mango...
> Your second method should work, but it's dependent on what your form
> looks like and how your table was created. You obviously have a key set
> for this column and you're trying to insert the same value twice, which
> makes an error.
>
> Show us what your form looks like, not the whole thing, just for the
> checkboxes. Also, what does your CREATE TABLE look like for the table
> your trying to insert this data into?
>
> ---John Holmes...
>
> > -----Original Message-----
> > From: Rob Packer [mailto:[EMAIL PROTECTED]]
> > Sent: Sunday, June 23, 2002 7:50 AM
> > To: [EMAIL PROTECTED]
> > Subject: [PHP] Insert an array into MySQL
> >
> > Hi, I've seen a few post for this same thing but I can't seem to get
> it
> > working. What I'm doing is taking a form with check boxes and putting
> them
> > into an array. Then I'm attempting to INSERT them into the db, one
> > checkbox
> > value per row.
> >
> > Okay,  well I've tries 2 ways that I think should work and they only
> > insert
> > the first value. They both produce this error "Duplicate entry '0' for
> key
> > 1" (which I don't understand) Anyway here is the code I'm trying...
> >
> > (I'm not trying to use both blocks of code, just one or the other)
> >
> > // First code
> > while(list($key,$value)=each($pagetype)){
> > //echo $value."<br>";//test
> > $links="INSERT INTO $username_links (links) VALUES ('$value')";
> > $insert=mysql_query($links,$connection);
> >
> > }
> >
> > // Second code attempt
> > $number=count($pagetype);
> > for($a=0;$a<$number;$a++){
> > $links="INSERT INTO $username_links (links) VALUES ('$pagetype[$a]')";
> > $insert=mysql_query($links) or die(mysql_error());
> > //echo $pagetype[$a];//test
> > }
> >
> >
> >
> >
> > Thanks in advance...Robert
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--- End Message ---
--- Begin Message ---
oops, sorry about the other post (I've got a baby that likes the
keyboard)...

Hi,

This is the form, which I had doubts about, but it seemed to put things into
the array correctly when I tested it by printing it out.
I can't see how, it will print
key=0
value=index.html
key=1
value=about.html
key=2
value=whats_new.html
when I test it and then have a duplicate key. It's saying that I have 2
$pagetype[0] correct? Anyhow, here's the form...

<INPUT TYPE=hidden NAME=pagetype[] VALUE='index.html'>Home Page <br>
<INPUT TYPE=checkbox NAME=pagetype[] VALUE='about.html'>About Page  <br>
<INPUT TYPE=checkbox NAME=pagetype[] VALUE='whats_new.html'>What's New
Page<br>
<INPUT TYPE=checkbox NAME=pagetype[] VALUE='contact.html'>Contact Page<br>
<INPUT TYPE=checkbox NAME=pagetype[] VALUE='favorite_links.html'>Favorite
Links <br>


The CREATE TABLE is this:
I define the table name from user input.

 $query_links="CREATE TABLE $username_links (id INT(4) not null, links
VARCHAR(20) not null, UNIQUE (id))";
 if(mysql_query($query_links,$connection)){
  echo "Links table created!<br>";
 }else{
  echo "no links table made<BR>";
 }




thanks,
 Rob




"John Holmes" <[EMAIL PROTECTED]> wrote in message
001201c21ab5$0df073a0$b402a8c0@mango">news:001201c21ab5$0df073a0$b402a8c0@mango...
> Your second method should work, but it's dependent on what your form
> looks like and how your table was created. You obviously have a key set
> for this column and you're trying to insert the same value twice, which
> makes an error.
>
> Show us what your form looks like, not the whole thing, just for the
> checkboxes. Also, what does your CREATE TABLE look like for the table
> your trying to insert this data into?
>
> ---John Holmes...
>
> > -----Original Message-----
> > From: Rob Packer [mailto:[EMAIL PROTECTED]]
> > Sent: Sunday, June 23, 2002 7:50 AM
> > To: [EMAIL PROTECTED]
> > Subject: [PHP] Insert an array into MySQL
> >
> > Hi, I've seen a few post for this same thing but I can't seem to get
> it
> > working. What I'm doing is taking a form with check boxes and putting
> them
> > into an array. Then I'm attempting to INSERT them into the db, one
> > checkbox
> > value per row.
> >
> > Okay,  well I've tries 2 ways that I think should work and they only
> > insert
> > the first value. They both produce this error "Duplicate entry '0' for
> key
> > 1" (which I don't understand) Anyway here is the code I'm trying...
> >
> > (I'm not trying to use both blocks of code, just one or the other)
> >
> > // First code
> > while(list($key,$value)=each($pagetype)){
> > //echo $value."<br>";//test
> > $links="INSERT INTO $username_links (links) VALUES ('$value')";
> > $insert=mysql_query($links,$connection);
> >
> > }
> >
> > // Second code attempt
> > $number=count($pagetype);
> > for($a=0;$a<$number;$a++){
> > $links="INSERT INTO $username_links (links) VALUES ('$pagetype[$a]')";
> > $insert=mysql_query($links) or die(mysql_error());
> > //echo $pagetype[$a];//test
> > }
> >
> >
> >
> >
> > Thanks in advance...Robert
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--- End Message ---
--- Begin Message ---
Nevermind, I got it. I had Unique for a field which made it mad.




"Rob Packer" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> oops, sorry about the other post (I've got a baby that likes the
> keyboard)...
>
> Hi,
>
> This is the form, which I had doubts about, but it seemed to put things
into
> the array correctly when I tested it by printing it out.
> I can't see how, it will print
> key=0
> value=index.html
> key=1
> value=about.html
> key=2
> value=whats_new.html
> when I test it and then have a duplicate key. It's saying that I have 2
> $pagetype[0] correct? Anyhow, here's the form...
>
> <INPUT TYPE=hidden NAME=pagetype[] VALUE='index.html'>Home Page <br>
> <INPUT TYPE=checkbox NAME=pagetype[] VALUE='about.html'>About Page  <br>
> <INPUT TYPE=checkbox NAME=pagetype[] VALUE='whats_new.html'>What's New
> Page<br>
> <INPUT TYPE=checkbox NAME=pagetype[] VALUE='contact.html'>Contact Page<br>
> <INPUT TYPE=checkbox NAME=pagetype[] VALUE='favorite_links.html'>Favorite
> Links <br>
>
>
> The CREATE TABLE is this:
> I define the table name from user input.
>
>  $query_links="CREATE TABLE $username_links (id INT(4) not null, links
> VARCHAR(20) not null, UNIQUE (id))";
>  if(mysql_query($query_links,$connection)){
>   echo "Links table created!<br>";
>  }else{
>   echo "no links table made<BR>";
>  }
>
>
>
>
> thanks,
>  Rob
>
>
>
>
> "John Holmes" <[EMAIL PROTECTED]> wrote in message
> 001201c21ab5$0df073a0$b402a8c0@mango">news:001201c21ab5$0df073a0$b402a8c0@mango...
> > Your second method should work, but it's dependent on what your form
> > looks like and how your table was created. You obviously have a key set
> > for this column and you're trying to insert the same value twice, which
> > makes an error.
> >
> > Show us what your form looks like, not the whole thing, just for the
> > checkboxes. Also, what does your CREATE TABLE look like for the table
> > your trying to insert this data into?
> >
> > ---John Holmes...
> >
> > > -----Original Message-----
> > > From: Rob Packer [mailto:[EMAIL PROTECTED]]
> > > Sent: Sunday, June 23, 2002 7:50 AM
> > > To: [EMAIL PROTECTED]
> > > Subject: [PHP] Insert an array into MySQL
> > >
> > > Hi, I've seen a few post for this same thing but I can't seem to get
> > it
> > > working. What I'm doing is taking a form with check boxes and putting
> > them
> > > into an array. Then I'm attempting to INSERT them into the db, one
> > > checkbox
> > > value per row.
> > >
> > > Okay,  well I've tries 2 ways that I think should work and they only
> > > insert
> > > the first value. They both produce this error "Duplicate entry '0' for
> > key
> > > 1" (which I don't understand) Anyway here is the code I'm trying...
> > >
> > > (I'm not trying to use both blocks of code, just one or the other)
> > >
> > > // First code
> > > while(list($key,$value)=each($pagetype)){
> > > //echo $value."<br>";//test
> > > $links="INSERT INTO $username_links (links) VALUES ('$value')";
> > > $insert=mysql_query($links,$connection);
> > >
> > > }
> > >
> > > // Second code attempt
> > > $number=count($pagetype);
> > > for($a=0;$a<$number;$a++){
> > > $links="INSERT INTO $username_links (links) VALUES ('$pagetype[$a]')";
> > > $insert=mysql_query($links) or die(mysql_error());
> > > //echo $pagetype[$a];//test
> > > }
> > >
> > >
> > >
> > >
> > > Thanks in advance...Robert
> > >
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>


--- End Message ---
--- Begin Message ---
You can use the HTTP_*_VARS for now, but they are depreciated. They will
work right now on most any version of PHP. 

I would just maintain two different versions, one for PHP 4.2+ and one
for earlier versions. Sure, it's a little more of a pain...though...

---John Holmes...

> -----Original Message-----
> From: Simon Troup [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, June 23, 2002 7:46 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] PHP 4.2
> 
> I've written a small freeware script that gets installed on a variety
of
> different platforms running various PHP versions.
> 
> I've read through the manual about the super global arrays and how
post
> and
> get vars are no longer registered by default, but am confused about
when
> it
> would be a good idea to "upgrade" the script.
> 
> If I change everything in the script and use $_GET and $_POST etc.
then
> those people who are still using earlier versions won't be able to
> upgrade.
> 
> Does anyone know what the uptake of the latest version is? What is
> everyone
> else doing about this? If I were developing for one client it wouldn't
be
> a
> problem as obviously you'd know what you were developing for.
> 
> I'd just like some feedback on when would be a good time to upgrade
the
> scripts while causing the minimum disruption and maintaining maximum
happy
> users.
> 
> Thanks
> 
> Zim
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
At 6/23/2002, you wrote:
>I've written a small freeware script that gets installed on a variety of
>different platforms running various PHP versions.
>
>I've read through the manual about the super global arrays and how post and
>get vars are no longer registered by default, but am confused about when it
>would be a good idea to "upgrade" the script.
>
>If I change everything in the script and use $_GET and $_POST etc. then
>those people who are still using earlier versions won't be able to upgrade.
>
>Does anyone know what the uptake of the latest version is? What is everyone
>else doing about this? If I were developing for one client it wouldn't be a
>problem as obviously you'd know what you were developing for.
>
>I'd just like some feedback on when would be a good time to upgrade the
>scripts while causing the minimum disruption and maintaining maximum happy
>users.

Hi,

I have used

if (isset($_SERVER)) $PHP_SELF = $_SERVER['PHP_SELF'];

to make $PHP_SELF work on all PHP's. Then you have to use $HTTP_GET_VARS 
and $HTTP_POST_VARS to pass vars. This way the script will work with 
globals on and off.

I really hate the way PHP 4.2 introduced the new default installation with 
globals "off", as they knew it will instantly force almost all coders to 
update their code. It took two weeks to make those changes on my rather 
large application.

Most virtual server users have no means to set PHP.INI to their liking so 
changes like that should be done in longer time span to let developers 
update the software _before_ changes in PHP happen.

Pekka
http://photography-on-the.net/



-------------------------
Pekka Saarinen
http://photography-on-the.net
-------------------------


--- End Message ---
--- Begin Message ---
on 23/06/02 11:06 PM, Pekka Saarinen ([EMAIL PROTECTED]) wrote:

> Most virtual server users have no means to set PHP.INI to their liking so
> changes like that should be done in longer time span to let developers
> update the software _before_ changes in PHP happen.


The changes and recommendations to make changes to your code were made in
the release notes of 4.1.0 I think, which was AGES ago.  My best guess is
mid-February 2002, but it may have been earlier.

http://www.php.net/release_4_1_0.php


If you do a clean install, yes, register globals will default to OFF, but
for an upgrade install of 4.2.x, it *should* pick up your old php.ini
setting of ON.

It took me a week or so to update my code as well, but I look at it as a
good move... my code is now more secure for starters.


Justin French



--- End Message ---
--- Begin Message ---
Hello all,

Does PHP have any built in functions to do simple profiling on a page?  Or
should
I just use $time1=time(); do_stuff(); $time2=time(); echo $time2-$time1;?

Thanks,

Jim Drabb

--
-------------------------------------------------------------
Never ask a geek why, just nod your head and slowly back away
-------------------------------------------------------------
James Drabb JR
Programmer Analyst
[EMAIL PROTECTED]


--- End Message ---
--- Begin Message ---
Yes, that's what I use, except I use microtime();

Justin French



on 23/06/02 11:49 PM, James Drabb ([EMAIL PROTECTED]) wrote:

> Hello all,
> 
> Does PHP have any built in functions to do simple profiling on a page?  Or
> should
> I just use $time1=time(); do_stuff(); $time2=time(); echo $time2-$time1;?
> 
> Thanks,
> 
> Jim Drabb
> 
> --
> -------------------------------------------------------------
> Never ask a geek why, just nod your head and slowly back away
> -------------------------------------------------------------
> James Drabb JR
> Programmer Analyst
> [EMAIL PROTECTED]
> 
> 

--- End Message ---
--- Begin Message ---

>So what's on "/usr/home/pagon/www/index.php on line 497" at a few lines
>before it?

         on line 497 theres the line:

          $linha=file('downs.txt');

         then the rest of the script as below.
         Before this line theres simple, very simple, html. I dont 
understand the error.


         Pag






> >
> >          <?
> > $linha=file('downs.txt');
> > $t=count($linha);
> > $l = $t - 1;
> > $fim = $l - 3;
> >
> > if ($l > 3)
> > {
> > $fim=$l - 3;
> > }
> > else {
> > $fim = 0;
> > }
> > for ($i = $l; $i >= $fim ; $i--) {
> >      $array=explode("|",$linha[$i]);
> >          print("<div align=\"left\">");
> >          print("<span class=\"data\">$array[0]</span>");
> >          print("<br>$array[1]<br>");
> >          print("</div><img src=\"spacer.gif\" height=\"3\">");
> >          }
> > ?>
> >
> >
> >          But from time to time, and with absolutely no visible reason, i
> > get this error:
> >
> >          Warning: php_network_getaddresses: getaddrinfo failed: No address
> > associated with hostname in /usr/home/pagon/www/index.php on line 497
> >
> > Warning: file("downs.txt") - Bad file descriptor in
> > /usr/home/pagon/www/index.php on line 497
> >


--- End Message ---
--- Begin Message ---

        Is it possible to code in PHP a small indicator on a site saying how many 
people are viewing that page at the moment?
        Sorry if its a silly question, but i am a newbie at PHP. If it is, could 
you point me in the good direction? i mean, some function or something.
        Thanks.

        Pag


--- End Message ---
--- Begin Message ---
Well, traditionally this would be done with sessions, and it's not exactly
the easiest topic for a newbie to get their head around.

It also never going to be a science -- how do you know when a user closes
their browser window or click onto another page?  You need to have clean-out
routines for "logged in" users who haven't had any activity for a while and
all sorts of other goodies.

Traditionally, most sites achieve things like "45 users and 12 guests
online" kinda thing using sessions, but I don't know if I've seen "45 users
looking this page right now" anywhere.


Hrm... a VERY NON SCIENTIFIC approach on a page-by-page basis would be to
log each hit on the page, and the time() that the hit was... boldly assume
that people will look at your page for 30 seconds or something, and keep a
counter of all hits within the last 30 seconds.  Like I said, not very geek
at all, not in any way scientific, but it's a quick fake.  Essentially, it's
more of a counter saying "48 hits in the last 30 seconds" than "48 people
looking at this page right now".


If you want to achieve this properly though, it's going to take you a few
hours to get your head around sessions, which can only be a good learning
experience any way.


Justin French


on 23/06/02 11:53 PM, Pag ([EMAIL PROTECTED]) wrote:

> Is it possible to code in PHP a small indicator on a site saying how many
> people are viewing that page at the moment?
> Sorry if its a silly question, but i am a newbie at PHP. If it is, could
> you point me in the good direction? i mean, some function or something.

--- End Message ---
--- Begin Message ---
Most questions like this depend more on your ability to think creatively 
than your experience with PHP, so don't let inexperience discourage you 
from exploring on your own.

First, decide what you consider to be "online" exactly. If I, for 
example, requested a page 30 seconds ago, you would probably consider me 
to be online, even though I could theoretically have closed my browser 
and gone to dinner since then.

If you're familiar with using a database, consider using the PHPSESSID 
(look into PHP sessions for more information on this) as a primary key 
in a table where the timestamp is kept and updated on each page request. 
To determine who is online, you could simply run a query on this table 
using your threshhold of idle time that you've determined to count as 
online.

There are plenty of different ways to approach this, and my 
early-morning example is probably not the best. Hopefully it gives you 
an idea though of what you need to accomplish.

Chris

Pag wrote:

>     Is it possible to code in PHP a small indicator on a site saying 
> how many people are viewing that page at the moment?


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

I've ma some atuh system to do such thing beside other
special functions, u have to store some session ids in some
db and then refresh timestamp for those session wich is still
active other delete after 30min or some other time.

-- 
bye,
 Uros                            mailto:[EMAIL PROTECTED]


Sunday, June 23, 2002, 3:53:46 PM, you wrote:


P>         Is it possible to code in PHP a small indicator on a site saying how many 
P> people are viewing that page at the moment?
P>         Sorry if its a silly question, but i am a newbie at PHP. If it is, could 
P> you point me in the good direction? i mean, some function or something.
P>         Thanks.

P>         Pag

--- End Message ---
--- Begin Message ---
I was running some speed tests on a page that returns 1000 records from
a db and spits them into a table.  I have output_buffering Off in my
php.ini file because of the statement below:

; Output buffering allows you to send header lines (including cookies) even
; after you send body content, at the price of slowing PHP's output layer a
; bit.  You can enable output buffering during runtime by calling the output
; buffering functions.  You can also enable output buffering for all files
by
; setting this directive to On.  If you wish to limit the size of the buffer
; to a certain size - you can use a maximum number of bytes instead of 'On',
as
; a value for this directive (ex., output_buffering=4096).
output_buffering = Off

However the page takes 7 seconds to load with output_buffering = Off
and 1 second with output_buffering = On!  What is up with that?  Have most
of you found output buffering faster?

Jim Drabb

--
-------------------------------------------------------------
Never ask a geek why, just nod your head and slowly back away
-------------------------------------------------------------
James Drabb JR
Programmer Analyst
[EMAIL PROTECTED]


--- End Message ---
--- Begin Message ---
What exactly are you measuring and how?

-----Original Message-----
From: James Drabb [mailto:[EMAIL PROTECTED]]
Sent: Sunday, June 23, 2002 9:09 AM
To: php-general
Subject: [PHP] output_buffering


I was running some speed tests on a page that returns 1000 records from
a db and spits them into a table.  I have output_buffering Off in my
php.ini file because of the statement below:

; Output buffering allows you to send header lines (including cookies) even
; after you send body content, at the price of slowing PHP's output layer a
; bit.  You can enable output buffering during runtime by calling the output
; buffering functions.  You can also enable output buffering for all files
by
; setting this directive to On.  If you wish to limit the size of the buffer
; to a certain size - you can use a maximum number of bytes instead of 'On',
as
; a value for this directive (ex., output_buffering=4096).
output_buffering = Off

However the page takes 7 seconds to load with output_buffering = Off
and 1 second with output_buffering = On!  What is up with that?  Have most
of you found output buffering faster?

--- End Message ---
--- Begin Message ---
I have upgraded from Apache 1.3.26 to 2.0.39 with PHP 4.2.1.
I am running FreeBSD 4.6 and everything was installed from
ports.

I have a PHP script called "go" (filename is without the .php extension)
and it is located in the root of my domain name:
http://www.mydomain.com/go

It's a script that my users launch with special arguments much like this:

http://www.mydomain.com/go/arg1/arg2/arg3

To get this to work, I've changed AllowOverride to All
in apache2's httpd.conf and I've added this to mydomain.com
.htaccess:

<FilesMatch "go$">
  ForceType application/x-httpd-php
</FilesMatch>

This same approach has worked perfectly for me
in apache 1.3.26, and it correctly launched
script "go" when someone opened URL such
as http://www.mydomain.com/go/something/somewhere

Unfortunately, with Apache 2.0.39 only
http://www.mydomain.com/go works okay, but
http://www.mydomain.com/go/bla/bla results in a 404 error.
(it looks as if Apache treats 'go' as directory, not as
a script - despite the settings in .htaccess - and therefore
it can't find the location)

I want http://www.mydomain.com/go/bla/bla
to launch the "go" script, just as it did with Apache 1.3.26.

I have even tried using the old 1.3.26 httpd.conf with
Apache 2.0.39 (after making the minor changes to make
it compatible with apache2), but it still won't work - same
problem :((

The only other config lines that IMHO could be possibly
related with this issue are:

RewriteEngine On
RewriteCond %{HTTP:Host} ^mydomain.com
RewriteRule ^(.*)$ http://www.mydomain.com$1 [L,R]

Am I missing something here?

Thanks!

= Simon


--- End Message ---
--- Begin Message ---
The only data returned by a browser in a "Cookie" header is the 
name/value pairs. So, your example would not pose a threat of any sort. 
The "Referer" and "User-Agent" are separate headers, but like all data 
from the client, they should also not be trusted.

If you have magic quotes enabled, you're probably safe. It is actually 
best not to just addslashes() again "to be sure" for any data. Rather, 
echo the value of your data to the screen during development, and test 
to be sure that your single quotes are escaped like you think they 
should be.

Chris

1LT John W. Holmes wrote:

>Yeah, magic_quotes will be enough, but it only handles GET, POST, and COOKIE
>data. I'm not sure what SERVER variables can be trusted, so it wouldn't hurt
>to addslash them...
>
>There isn't much of a risk to your query, but someone could still mess
>things up. If they formatted a cookie like
>
>$_COOKIE['tececo_stats'] =
>"bad_data','bad_time','bad_host','bad_referrer','bad_agent')#";
>
>it would allow them to insert bad data into your table...
>

--- End Message ---
--- Begin Message ---
> The only data returned by a browser in a "Cookie" header is the
> name/value pairs. So, your example would not pose a threat of any
sort.
> The "Referer" and "User-Agent" are separate headers, but like all data
> from the client, they should also not be trusted.
> 
> If you have magic quotes enabled, you're probably safe. It is actually
> best not to just addslashes() again "to be sure" for any data. Rather,
> echo the value of your data to the screen during development, and test
> to be sure that your single quotes are escaped like you think they
> should be.

Exactly... the name would be "tececo_stats" and the value would be
"bad_data','bad_time','bad_host','bad_referrer','bad_agent')#"

If slashes are not getting added to that data, either by magic quotes or
by addslashes(), then he's open to getting bad data inserted into his
table...

If magic_quotes_gpc is ON, then you're fine...

---John Holmes...

> Chris
> 
> 1LT John W. Holmes wrote:
> 
> >Yeah, magic_quotes will be enough, but it only handles GET, POST, and
> COOKIE
> >data. I'm not sure what SERVER variables can be trusted, so it
wouldn't
> hurt
> >to addslash them...
> >
> >There isn't much of a risk to your query, but someone could still
mess
> >things up. If they formatted a cookie like
> >
> >$_COOKIE['tececo_stats'] =
> >"bad_data','bad_time','bad_host','bad_referrer','bad_agent')#";
> >
> >it would allow them to insert bad data into your table...
> >
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
> From: <[EMAIL PROTECTED]>
>
> When I am in page A (or one of it's children) I wish to show it's one level of
> children like so:
> 
> Page A
>   Child 1
>   Child 2
>   etc...
> Page B
> 
> When I am in page B (or one of it's children) I wish to show it's one level of
> children like so:
> 
> Page A
> Page B
>   Child 1
>   Child 2
>   etc...
>  
> Do you get the picture?
>  
> I have a db with link url, id, parent id and title
>  
> does any one know of a simple function or something to do this for one level?

I wrote the code below for a menu system like this on a recent project:

----------

// declare class (s)elect (l)ist
class sl
{
  var $query;
  var $result;
  var $row;
  function set_query($new_value)
  {
    $this->query = $new_value;
  }
}
// create object (c)ategory (s)elect (l)ist
$csl = new sl();
// create object (s)ubcategory (s)elect (l)ist
$ssl = new sl();
// set query for object csl to display main categories
$csl->set_query("SELECT ID, Name FROM Categories WHERE ParentID=0");
$csl->result = mysql_query($csl->query);
// display the menu
while ($csl->row = mysql_fetch_array($csl->result))
{
  $ParentCatID=$csl->row["ID"];
  if ($csl->row["ID"] == $MainCatID)
  {
    echo("<p class=\"menuselected\">" .
      "<a href=$PHP_SELF?MainCatID=$ParentCatID>" .
      $csl->row["Name"] . "</a></p>\n");
    // set query for object (s)ubcategory (s)elect (l)ist
    $ssl->set_query("SELECT ID, Name, ParentID FROM Categories " .
      "WHERE ParentID=$MainCatID");
    $ssl->result = mysql_query($ssl->query);
    // display subcategories (submenu)
    while ($ssl->row = mysql_fetch_array($ssl->result))
    {
      $ParentCatID = $ssl-row["ParentID"];
      $ChildCatID = $ssl->row["ID"];
      if ($ssl->row["ID"] == $SubCatID)
      {
        echo("<p class=\"submenuselected\">" .
          "<a href=$PHP_SELF?MainCatID=" .
          "$ParentCatID&SubCatID=$ChildCatID>" .
          $ssl->row["Name"] . "</a></p>\n");
      }
      else
      {
        echo("<p class=\"submenu\">" .
          "<a href=$PHP_SELF?MainCatID=" .
          "$ParentCatID&SubCatID=$ChildCatID>" .
          $ssl->row["Name"] . "</a></p>\n");
      }
    }
  }
  // finish main category display
  else
  {
    echo("<p class=\"menu\">" .
      "<a href=$PHP_SELF?MainCatID=$ParentCatID>" .
      $csl->row["Name"] . "</a></p>\n");
  }
}

----------

Main menu categories have a ParentID assignment of 0 in the db. A select is
done of all ID & Name in the Categories table where ParentID=0. The menu is
displayed with names linked to recalling the script and passing the variable
$MainCatID -- the ID of the category. When the script is called with
$MainCatID set (when a main menu category is selected), the menu name with
ID matching $MainCatID is assigned a style class to distinguish visually
that it's selected. Also at this point another selection is done from
Categories where ParentID=$MainCatID, thus creating the list of
subcategories for the selected main category. The subcategories are also
displayed with links back to the script passing the variable $MainCatID
again plus the variable $SubCatID. When the script is called with $SubCatID
set, the submenu name with ID equal to $SubCatID is also class-styled to
indicate the selection.

The main page display (in this case for a products catalog) is generated by
other selection queries based on $MainCatID and $SubCatID.

--
Lowell Allen

--- End Message ---
--- Begin Message ---
When you see document contains no data like that, the most likely cause 
is an endless loop. So, for whatever, reason, it seems that  your 
conditional statement is returning true every time.

Remove the "Location" header for now, and replace that line with:

echo "<h1>Redirecting to http://blah.com/sendheader.php</h1>";
exit;

This will allow you to see whether you are returning that "Location" 
header to the client under the different cases. My guess is that you 
will see this on the screen even when you don't expect to. That should 
give you a starting point for debugging.

Chris

Thomas E. Ruth wrote:

>Hi, 
>
>I'm having trouble getting a script working right in netscape 4.x and
>was wondering if anybody knew a workaround, or fix.
>
>If I have a script called "sendheader.php" with the following:
>
><?
>if (! isset($GLOBALS[sendheader])) {
>       header("Location: http://blah.com/sendheader.php";);
>       exit;
>}
>
>echo "blah";
>?>
>
>Load the script in netscape 4.x with
>http://blah.com/sendheader.php?sendheader=0. Then load the script like
>http://blah.com/sendheader.php and netscape returns "Document contains
>no data".
>

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

I am new to php, I would like to create a function that when called
sends text from a text box as a query to a remote cgi script ,e.g
http://www.anydomain.com/cgi-bin/script.cgi, and return the results as a
  variable so that i can echo the returned variable to an html page.

I would appreciate any help on this

Thanks



--- End Message ---
--- Begin Message ---
> I am new to php, I would like to create a function that when called
> sends text from a text box as a query to a remote cgi script ,e.g
> http://www.anydomain.com/cgi-bin/script.cgi, and return the results as
a
>   variable so that i can echo the returned variable to an html page.

<?
$contents = "";
$text = "whatever...";

$ftext = urlencode($text);

$fp = fopen("http://www.example.com/cgi-bin/script.cgi?text="; . $ftext,
"r");

while($data = fread($fp,1000))
{ $contents .= $data; }

fclose ($fd);

?>

The response is now in $contents. Adapt to your needs. 

---John Holmes...

--- End Message ---
--- Begin Message ---
Hey all,

I would like to place some files on my site and use PHP to track how many
users have downloaded those files.

Is this possible?

Is the PHP code only placed on this one page?
I don't know PHP all that well, but my host supports it, and I want to track
downloads, also to be able ot have them shown on the page (if possible)

Thanks for any help,

Kevin J


--
http://www.wishpocket.com



--- End Message ---
--- Begin Message ---
On Sun, 23 Jun 2002, Kevin J wrote:

> Hey all,
> 
> I would like to place some files on my site and use PHP to track how many
> users have downloaded those files.
> 
> Is this possible?

Approach the problem logically:

1) You have a series of files that you want people to download.
2) You want to track which files are downloaded.
3) You don't want people accessing the files directly.

So, a file called download.php.
Accepts a parameter - the file name to make available.
Logs an entry of IP and file (and whatever else) to a file / database / 
whatever.
Makes the file available to the user - but the path is hidden / created on 
the fly so that a particular file cannot be pulled without going through the 
script.

The actual code is left as an excercise for the reader.

--- End Message ---
--- Begin Message ---
Hello,

My fault, I didn't state that i was a complete Newbie to PHP.

I am looking at scripts and realize that I need to use a database for this,
etc... so I am just gonna forget the whole thing.

Thanks anyways

Kevin J

"Duncan Hill" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> On Sun, 23 Jun 2002, Kevin J wrote:
>
> > Hey all,
> >
> > I would like to place some files on my site and use PHP to track how
many
> > users have downloaded those files.
> >
> > Is this possible?
>
> Approach the problem logically:
>
> 1) You have a series of files that you want people to download.
> 2) You want to track which files are downloaded.
> 3) You don't want people accessing the files directly.
>
> So, a file called download.php.
> Accepts a parameter - the file name to make available.
> Logs an entry of IP and file (and whatever else) to a file / database /
> whatever.
> Makes the file available to the user - but the path is hidden / created on
> the fly so that a particular file cannot be pulled without going through
the
> script.
>
> The actual code is left as an excercise for the reader.
>


--- End Message ---
--- Begin Message ---

KJ> I am looking at scripts and realize that I need to use a database for this,
KJ> etc... so I am just gonna forget the whole thing.

Unfortunate, that giving up so easily!  You can also do exactly the
same type of tracking in a plain text file, if you do not have access
to a db.  Substitute opening a file and writing a line, for inserting
a record into a db.

Plenty of examples in the manual. (ok, at least 1)


- Julie

--> Julie Meloni
--> [EMAIL PROTECTED]
--> www.thickbook.com

Find "Sams Teach Yourself MySQL in 24 Hours" at
http://www.amazon.com/exec/obidos/ASIN/0672323494/thickbookcom-20

--- End Message ---
--- Begin Message ---
Well see I don't know where to begin all this.

I have a plain html page, with links to the songs: ../music/song.mp3

And I woudn't know where to start, in creating a php track file, or a text
file to keep track.
I am able to have MySQL on the hosting server, which I am going to enable...
and from there I am lost.

Sorry for giving up, but it seems to hard for me, plus I only have about 2
weeks to learn PhP, if I wanted to implement this... I don't think that is
possible.

Kevin J

"Julie Meloni" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>
> KJ> I am looking at scripts and realize that I need to use a database for
this,
> KJ> etc... so I am just gonna forget the whole thing.
>
> Unfortunate, that giving up so easily!  You can also do exactly the
> same type of tracking in a plain text file, if you do not have access
> to a db.  Substitute opening a file and writing a line, for inserting
> a record into a db.
>
> Plenty of examples in the manual. (ok, at least 1)
>
>
> - Julie
>
> --> Julie Meloni
> --> [EMAIL PROTECTED]
> --> www.thickbook.com
>
> Find "Sams Teach Yourself MySQL in 24 Hours" at
> http://www.amazon.com/exec/obidos/ASIN/0672323494/thickbookcom-20
>


--- End Message ---
--- Begin Message ---
On Sun, 23 Jun 2002, Kevin J wrote:

> Sorry for giving up, but it seems to hard for me, plus I only have about 2
> weeks to learn PhP, if I wanted to implement this... I don't think that is
> possible.

The manual abounds with examples on how to 
a) connect to a database
b) read / write data in files

Of course, the simpler way is to just analyse the web server logs for hits 
on the files in question.

--- End Message ---
--- Begin Message ---
i have a opensource redirect script that can easily be adapted to track downloads - 
just need to
replace a absolute url for a file name.

check it out at http://user:[EMAIL PROTECTED]/lab

cheers
Henry


--- End Message ---
--- Begin Message ---
hi,
how come when i make a dir thus

mkdir($basedir,0777);

cute can't then chmod or delete said dir.
also vice versa : when i create a dir with cute
with 777 access php can't do anything with it.
it's very annoying.
--- End Message ---
--- Begin Message ---
This is a common question, related to the lack of understanding of
client/server architectures I believe.

PHP is all server side - a browser is all client side.

Servers can send data only to the browser, nothing else. The server can
inquire and gather data from text files and databases, but it will format
the data into a particular protocol (HTTP most often) and send it to the
browser. The data may even include lines of text from a language that the
browser understands, like JavaScript. Or it might be XML data and the
corresponding XSLT instructions. But ... it can't affect the browser
directly. Only the embedded instructions that the browser understands can
actually affect anything on the browser.

The browser looks at the stream of data provided by the server and decides
on-the-fly what to do with it. If it sees JavaScript instructions, it may
decide to interpret them and do some particular action. Or it may decide
that it doesn't want to play with JavaScript today and just ignore them. It
may see the XML/XSLT and decide to do something - but it doesn't have to.
This, of couse, is the bane of Web programmers everywhere. What does the
browser understand, and what does it do with the data.

PHP allows us to write programs eaisy on the server to make some decisions
on what to send a browser, but it cannot act directly on the browser. We
must depend (somehow) on the browser interpreting what we tell it and then
acting in a particular way.

-----Original Message-----
From: Jason Wong [mailto:[EMAIL PROTECTED]]
Sent: Sunday, June 23, 2002 12:17 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] is there a function like javascript's window.open in
PHP


On Sunday 23 June 2002 07:21, Burak Delice wrote:
> hi,
>
> I wonder that is there a PHP function like window.open() into Javascript?

No.

--
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
One thought driven home is better than three left on base.
*/


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


--- End Message ---
--- Begin Message ---
Mark, thankyou very very much your detailed explanations about my
complexity. And thank you for gave your time to write it.

I think, I have to start first step about scripts :)


"Mark Charette" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> This is a common question, related to the lack of understanding of
> client/server architectures I believe.
>
> PHP is all server side - a browser is all client side.
>
> Servers can send data only to the browser, nothing else. The server can
> inquire and gather data from text files and databases, but it will format
> the data into a particular protocol (HTTP most often) and send it to the
> browser. The data may even include lines of text from a language that the
> browser understands, like JavaScript. Or it might be XML data and the
> corresponding XSLT instructions. But ... it can't affect the browser
> directly. Only the embedded instructions that the browser understands can
> actually affect anything on the browser.
>
> The browser looks at the stream of data provided by the server and decides
> on-the-fly what to do with it. If it sees JavaScript instructions, it may
> decide to interpret them and do some particular action. Or it may decide
> that it doesn't want to play with JavaScript today and just ignore them.
It
> may see the XML/XSLT and decide to do something - but it doesn't have to.
> This, of couse, is the bane of Web programmers everywhere. What does the
> browser understand, and what does it do with the data.
>
> PHP allows us to write programs eaisy on the server to make some decisions
> on what to send a browser, but it cannot act directly on the browser. We
> must depend (somehow) on the browser interpreting what we tell it and then
> acting in a particular way.
>
> -----Original Message-----
> From: Jason Wong [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, June 23, 2002 12:17 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] is there a function like javascript's window.open in
> PHP
>
>
> On Sunday 23 June 2002 07:21, Burak Delice wrote:
> > hi,
> >
> > I wonder that is there a PHP function like window.open() into
Javascript?
>
> No.
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
>
> /*
> One thought driven home is better than three left on base.
> */
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--- End Message ---
--- Begin Message ---
Anyone has any comparative info between Smarty and Roadsend frameworks?

I saw them mentioned on an email, along with horde and binarycloud, and
they look interesting.

I have looked at horde and found it difficult to get even
the basics due to lacking documentation and configuration files which I
felt were not well organized. BinaryCloud seems very "large"
and with a very big learning curve.


--- End Message ---
--- Begin Message ---
You could use the mail class by Manuel Lemos on php.upperdesign.com if you
need cc/bcc and attachments. I've been using it for quite some time now with
good results.

Christoph

Lance wrote:
> ok. thanks for the info. guess i have to wait till it hit stable
> version before deploying it on live server. for now, it's byebye to
> CC/BCC/Attachments.


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

I'd like to write a function that will take a string of characters and 
output it in a phone number format (xxx)xxx-xxxx and one for credit 
cards xxxx-xxxx-xxxx-xxxx. What I have below will currently remove 
non-numeric characters from the string, but I'm not sure how to do the 
rest of the formatting. Any help would be appreciated.

By the way, any recommendations for good php tutorials for beginners?

Thanks,
Corinne


<html>
<head>
        <title></title>
</head>

<body>
<?
        function formatPhoneNum($prmValue)
        {
        
        $retrunValue='';
        
        for($i=0; $i<strlen($prmValue); $i++)
        {
        
        if(ereg('[0-9]', substr($prmValue, $i,1)))
        
        $returnValue.=substr($prmValue,$i,1);
        }
        
        return $returnValue;
        
        }
        ?> 
        <?
                $phoneNum= '415123kjdf4567';
        ?>
        
        <p>Phone Number: <?=formatPhoneNum($phoneNum)?></p>
</body>
</html>


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

Maybe you have a look at the sprintf function in PHP
http://www.php.net/manual/nl/function.sprintf.php
It returns a string produced according to a formatting string (i.e.
phonenumber) format.

Also have look at the other formatting functions in PHP.

Bye,
Sacha Telgenhof


"Corinne Shea" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi,
>
> I'd like to write a function that will take a string of characters and
> output it in a phone number format (xxx)xxx-xxxx and one for credit
> cards xxxx-xxxx-xxxx-xxxx. What I have below will currently remove
> non-numeric characters from the string, but I'm not sure how to do the
> rest of the formatting. Any help would be appreciated.
>
> By the way, any recommendations for good php tutorials for beginners?
>
> Thanks,
> Corinne
>
>
> <html>
> <head>
> <title></title>
> </head>
>
> <body>
> <?
> function formatPhoneNum($prmValue)
> {
>
> $retrunValue='';
>
> for($i=0; $i<strlen($prmValue); $i++)
> {
>
> if(ereg('[0-9]', substr($prmValue, $i,1)))
>
> $returnValue.=substr($prmValue,$i,1);
> }
>
> return $returnValue;
>
> }
> ?>
> <?
> $phoneNum= '415123kjdf4567';
> ?>
>
> <p>Phone Number: <?=formatPhoneNum($phoneNum)?></p>
> </body>
> </html>
>
>


--- End Message ---
--- Begin Message ---
preg_replace will do it.

$returnValue = preg_replace("/(\d{3})(\d{3})(\d{4})/","($1)$2-$3",$returnValue);

(\d{3})(\d{3})(\d{4}) = $0 or \\0 we aren't using this match

we are using the subpatterns in brackets
(\d{3}) =$1 or \\1 matches 3 numbers
(\d{3}) =$2 or \\2 matches 3 numbers
(\d{4}) =$3 or \\3 matches 4 numbers

which we use to make the replacement
($1)$2-$3

http://za2.php.net/manual/en/function.preg-replace.php

so that's the phone number, I'll leave the cc to you.

Paul Roberts
[EMAIL PROTECTED]
++++++++++++++++++++++++

<?php
function formatPhoneNum($prmValue)
{

$retrunValue='';

for($i=0; $i<strlen($prmValue); $i++)
{

if(ereg('[0-9]', substr($prmValue, $i,1)))

$returnValue.=substr($prmValue,$i,1);
}
$returnValue = preg_replace("/(\d{3})(\d{3})(\d{4})/","($1)$2-$3",$returnValue);
return $returnValue;

}
?> 
<?php
$phoneNum= '415123kjdf4567';
?>

<p>Phone Number: <?php echo formatPhoneNum($phoneNum); ?></p>
</body>
</html>
----- Original Message ----- 
From: "Corinne Shea" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, June 23, 2002 8:06 PM
Subject: [PHP] Formatting phone numbers


Hi,

I'd like to write a function that will take a string of characters and 
output it in a phone number format (xxx)xxx-xxxx and one for credit 
cards xxxx-xxxx-xxxx-xxxx. What I have below will currently remove 
non-numeric characters from the string, but I'm not sure how to do the 
rest of the formatting. Any help would be appreciated.

By the way, any recommendations for good php tutorials for beginners?

Thanks,
Corinne


<html>
<head>
<title></title>
</head>

<body>
<?
function formatPhoneNum($prmValue)
{

$retrunValue='';

for($i=0; $i<strlen($prmValue); $i++)
{

if(ereg('[0-9]', substr($prmValue, $i,1)))

$returnValue.=substr($prmValue,$i,1);
}

return $returnValue;

}
?> 
<?
$phoneNum= '415123kjdf4567';
?>

<p>Phone Number: <?=formatPhoneNum($phoneNum)?></p>
</body>
</html>



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





--- End Message ---
--- Begin Message ---
Corinne Shea wrote:

>Hi,
>
>I'd like to write a function that will take a string of characters and 
>output it in a phone number format (xxx)xxx-xxxx and one for credit 
>cards xxxx-xxxx-xxxx-xxxx.
>
This is actually very easy to do if all you want to do is format, 
meaning you have already validated the data and can be assured that you 
have ten digits (or 16 for credit cards).

$phone_num="8005551212";
$formatted_phone_num="(" . substr($phone_num, "0", "3") . ") " . 
substr($phone_num, "3", "3") . "-" . substr($phone_num, "6", "4");

I'm sure there are other ways to achieve the same result, but you 
basically want to look at string functions that allow you to slice a 
phone number into whatever parts you want (area code, prefix, suffice 
for US numbers) and then create a string formatted however you want.

Chris

--- End Message ---
--- Begin Message ---
I have gotten JPGraph to work if I suppress the output of errors. I am using
the example of backgroundex02.php.
If I add the line "error_reporting(0);" at the top, I get the graph, if I
remove it...I get the following error;

"
Warning: Use of undefined constant LC_TIME - assumed 'LC_TIME' in
../jpgraph.php on line 474

Warning: Use of undefined constant LC_TIME - assumed 'LC_TIME' in
../jpgraph.php on line 475

Warning: Use of undefined constant LC_TIME - assumed 'LC_TIME' in
../jpgraph.php on line 495

Warning: Cannot add header information - headers already sent by (output
started at ../jpgraph.php:474) in ../jpgraph.php on line 4257
?PNG

"

I assume this is a variable for Local Time, but I don't know where to set
it. Can anyone help me please.


--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] (Jtjohnston), il 06 lug 2002, trasse un 
profondo sospiro e disse:

[cut]

Check your date.
Bye.
--- End Message ---
--- Begin Message ---
Hi,

I am saving the result of a query on a text file.  Then I want to open it
with excel.

At the moment, when I open it with excel, all results appear in one very
long line.  How could I insert a "new line" character at the end of each
record?

Thanks

Alfredo


--- End Message ---
--- Begin Message ---
On Fri, 21 Jun 2002, Alfredo wrote:

> Hi,
> 
> I am saving the result of a query on a text file.  Then I want to open it
> with excel.
> 
> At the moment, when I open it with excel, all results appear in one very
> long line.  How could I insert a "new line" character at the end of each
> record?

Unix considers a line feed to be \n

Windows/DOS use \r\n

--- End Message ---
--- Begin Message ---

"\n" is a newline character, "\r" is a carriage return.

$line = "This is a line with a newline character.\n";

You can find it in the manual here:
http://www.php.net/manual/en/language.types.string.php

mh.



On Fri, 21 Jun 2002, Alfredo wrote:

> Hi,
>
> I am saving the result of a query on a text file.  Then I want to open it
> with excel.
>
> At the moment, when I open it with excel, all results appear in one very
> long line.  How could I insert a "new line" character at the end of each
> record?
>
> Thanks
>
> Alfredo
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
I think you can also use \t to separate the data into the various columns
needed by excel
----- Original Message -----
From: "Alfredo" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, June 21, 2002 7:55 PM
Subject: [PHP] How to put a "new line" character with fputs($birthday_file,
$content);


> Hi,
>
> I am saving the result of a query on a text file.  Then I want to open it
> with excel.
>
> At the moment, when I open it with excel, all results appear in one very
> long line.  How could I insert a "new line" character at the end of each
> record?
>
> Thanks
>
> Alfredo
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---

I am trying to sort some old data files that have turned up, records of
who lived where in my town, they are quite incomplete, and I have to
reformat the information in a 20k line database, and could really do
with a little help

the tables and basic data is like this:

ID , Address, Name, Relation
1, market st, fred waters, head
2, market st, mrs waters, wife
3, market st, paul waters, son
4, market st, jim wheeler, head
5, market st, mrs wheeler, wife
6, market st, ann wheeler, dau


my problem is that about 5k of the address's are not unique I.e. there
may be a whole street of people with their address listed as 'Market
Street' and there isn't a good way to tell a whole household of people
in the street from the next-door household, except that each 'household'
only has 1 'Head' as its value in the 'relation' column, and these
records are almost all correctly formatted.

so, I want to alter the database table to be

ID , Address, Name, Relation, household

this will allow me to count and number the relation tables 'Heads'
entries, I want to keep the same count number for all relations/visitors
of that 'Household' until the next instance of 'Head' in the 'Relation'
column, so that the household count would increment as below:

ID , Address, Name, Relation, household
1, market st, fred waters, head, 1
2, market st, mrs waters, wife, 1
3, market st, paul waters, son, 1
4, market st, jim wheeler, head, 2
5, market st, mrs wheeler, wife, 2
6, market st, ann wheeler, dau, 2

by dong this, I can easily search and find all the people that are a
'family unit', in any particular house, even if the address field, isn't
unique, i.e. ,market st, instead of #4 market st.

so, I know what I want to do, but am totally at a loss how to do it. I
know I need to cycle through the whole of the 20k records, updating the
new 'household' table with a number that increments by +1 and use that
number for all entries until after each instance of the data being
'head'.
when if its incremented by +1, it will be another family unit.

Can anyone help me with how to do this, I am not sure whether it will
need php to read and insert the incrementing number, or if its possible
with just a mysql statement ?

any help at all will be appreciated

Steven







--- End Message ---
--- Begin Message ---
Hi all,
 
A couple of days ago, I’ve been starting to organize all my scripts into
functions within libraries, and got into a problem this morning. Now, I
don’t know if this is a bug or it’s just me getting confused. I got the
problem when calling two functions – one gets variables from the other –
within the same page.
 
That is, I have a mainusers.php page, which only calls for functions
instead of writing them all together inside that page. At one step, it
calls for an “adduser” function which brings a table that let the
administrator insert a new user. After the submit button is pressed, it
calls for a function called “useradded” which resides in the same
library as the “adduser” function. This useradded function queries the
database, inserting the user. The problem is that it does not get the
HTTP_POST_VARS although they are being passed according to phpinfo.php.
 
The structure is this:
 
Project directory
 
>Library Directory
>>addlib.php
>>>adduser() function
>>>useradded() function
 
>Pages directory
>>mainusers.php
>>>first calls for adduser()
>>>and then for useradded()
 
Now, the thing is if I, instead of calling the function, write the query
directly in the mainusers.php page, the variables are get well and
written into the database. I don’t know if this makes much sense, but
the thing is… Isn’t PHP forced to pass those variables before the
function is called so when they’re needed they can be get through
HTTP_POST_VARS or just $var_name which I like using?
 
Thanks…
 
Cesar Aracena <mailto:[EMAIL PROTECTED]> 
CE / MCSE+I
Neuquen, Argentina
+54.299.6356688
+54.299.4466621
 
--- End Message ---
--- Begin Message ---
In article <000c01c21b02$4b69e1b0$1aed0dd1@gateway>,
 [EMAIL PROTECTED] (César aracena) wrote:

>  I have a mainusers.php page, which only calls for functions
> instead of writing them all together inside that page. At one step, it
> calls for an “adduser” function which brings a table that let the
> administrator insert a new user. After the submit button is pressed, it
> calls for a function called “useradded” which resides in the same
> library as the “adduser” function. This useradded function queries the
> database, inserting the user. The problem is that it does not get the
> HTTP POST VARS although they are being passed according to phpinfo.php.

Without an example to look at, I may be mis-understanding your situation.  
But it sounds like this may be a scoping issue: trying to use a global 
($HTTP_POST_VARS) within a function without using the special "global" 
keyword. 

This won't work:

function adduser()
   {
   echo "LOCAL SCOPE: " . $HTTP_POST_VARS['user'];
   }
adduser();

This will:

function adduser()
   {
   global $HTTP_POST_VARS['user'];
   echo "GLOBAL SCOPE: " . $HTTP_POST_VARS['user'];
   }
adduser();

If this is the problem you're having, you can find more information at:

http://php.net/variables.scope
http://php.net/global

-- 
CC
--- End Message ---
--- Begin Message ---
If the code is in a function then don't you need to call
global $HTTP_POST_VARS;
at the top of the function so that it knows you can use that varible?

Andrew
----- Original Message -----
From: "César Aracena" <[EMAIL PROTECTED]>
To: "PHP General List" <[EMAIL PROTECTED]>
Sent: Sunday, June 23, 2002 11:06 PM
Subject: [PHP] Is this a BUG?


Hi all,

A couple of days ago, I've been starting to organize all my scripts into
functions within libraries, and got into a problem this morning. Now, I
don't know if this is a bug or it's just me getting confused. I got the
problem when calling two functions - one gets variables from the other -
within the same page.

That is, I have a mainusers.php page, which only calls for functions
instead of writing them all together inside that page. At one step, it
calls for an "adduser" function which brings a table that let the
administrator insert a new user. After the submit button is pressed, it
calls for a function called "useradded" which resides in the same
library as the "adduser" function. This useradded function queries the
database, inserting the user. The problem is that it does not get the
HTTP_POST_VARS although they are being passed according to phpinfo.php.

The structure is this:

Project directory

>Library Directory
>>addlib.php
>>>adduser() function
>>>useradded() function

>Pages directory
>>mainusers.php
>>>first calls for adduser()
>>>and then for useradded()

Now, the thing is if I, instead of calling the function, write the query
directly in the mainusers.php page, the variables are get well and
written into the database. I don't know if this makes much sense, but
the thing is. Isn't PHP forced to pass those variables before the
function is called so when they're needed they can be get through
HTTP_POST_VARS or just $var_name which I like using?

Thanks.

Cesar Aracena <mailto:[EMAIL PROTECTED]>
CE / MCSE+I
Neuquen, Argentina
+54.299.6356688
+54.299.4466621



--- End Message ---
--- Begin Message ---
I can't seem to figure out how to use array_splice to replace an element 
while retaining the key... instead it replaces the key with 0

for example...

$foo=array("color"=>"blue","fruit"=>"apple","foo"=>"bar");
array_splace($foo,1,1,array("car"=>"pinto"));

yields...

Array
(
    [color] => blue
    [0] => pinto
    [foo] => bar
)


instead of

Array
(
    [color] => blue
    [car] => pinto
    [foo] => bar
)

...
Is there a quick and dirty way to do this? or does it require chopping 
the array up into to parts and merging them back together again.

--- End Message ---
--- Begin Message ---
I figured it out, not what i'd wanted it to be, but it works, if anyone 
can improve upon it, please let me know.

<?php

function array_key_replace($foo,$original,$replacement,$replacement_value) {

     $bar=array();

     foreach($foo as $key=>$value) {
         if ($key==$original) {
             $bar[$replacement]=$replacement_value;
         }
         else $bar[$key]=$value;
     }

     return $bar;

}

$foo=array("color"=>"blue","fruit"=>"apple","foo"=>"bar");

$foo=array_key_replace($foo,"fruit","car","pinto");

?>

Enjoy! ;)

Austin W. Marshall wrote:
> I can't seem to figure out how to use array_splice to replace an element 
> while retaining the key... instead it replaces the key with 0
> 
> for example...
> 
> $foo=array("color"=>"blue","fruit"=>"apple","foo"=>"bar");
> array_splace($foo,1,1,array("car"=>"pinto"));
> 
> yields...
> 
> Array
> (
>    [color] => blue
>    [0] => pinto
>    [foo] => bar
> )
> 
> 
> instead of
> 
> Array
> (
>    [color] => blue
>    [car] => pinto
>    [foo] => bar
> )
> 
> ...
> Is there a quick and dirty way to do this? or does it require chopping 
> the array up into to parts and merging them back together again.
> 



--- End Message ---
--- Begin Message ---
I just download apache 1.3.x latest, php latest andmy sql latest. (win32
env)

Which packages I need to download now to enable gd-library for graphics ?
and zlib ?

I wanna enable png creation . .

where can I find the compiled dlls for those ?

I found a dll called gds32.dll in the dlls dir of php is that one for the gd
library ?

In the php file then you have to enable the extensions... shall i add
gds32.dll then in the list there ?

Thanks in advance...



--
~~~~~~~~~~~~~~~~

Sapilas@/dev/pinkeye

~~~~~~~~~~~~~~~~


--- End Message ---

Reply via email to