Re: [PHP] Beginner question

2009-08-25 Thread Ashley Sheridan
On Mon, 2009-08-24 at 23:16 -0600, mike bode wrote:
 I am trying to use PHP on my web site I am developing now. I have installed 
 Apache 2.2 and PHP 5.2. My problem is that I can execute PHP code embedded 
 in my HTML code, but I can't execute the same cose when I put it into a 
 separate .php file that i then call from within the html code. for example:
 
 I have a html file with
 
 body
 ?php
 echo Printing with php;
 ?
 ?body
 
 and it works fine.
 
 When I take out the php code and put it inot a file pp.php, and I call that 
 file with my browser (localhost/pp.php), it works, too.
 
 But when I change the html code to:
 
 body
 script type=text/javascript src=pp.php/script
 /body
 
 I get a blank page. this is probably something really stupid, but I have 
 been wrecking my head for days now, and I can't figure it out. anybody has 
 an idea? 
 
 
Yes, this is not how you use PHP! PHP isn't embedded in HTML, it's
actually the other way round.

You should make the main page a .php page and from there you can include
the necessary HTML parts like so:

?php
include includes/header.html;

// body code here

include includes/footer.html;
?

Thanks,
Ash
http://www.ashleysheridan.co.uk




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



RE: [PHP] Beginner question

2009-08-25 Thread abdulazeez alugo



 To: php-general@lists.php.net
 From: mikebo...@hotmail.com
 Date: Mon, 24 Aug 2009 23:16:02 -0600
 Subject: [PHP] Beginner question
 
 I am trying to use PHP on my web site I am developing now. I have installed 
 Apache 2.2 and PHP 5.2. My problem is that I can execute PHP code embedded 
 in my HTML code, but I can't execute the same cose when I put it into a 
 separate .php file that i then call from within the html code. for example:
 
 I have a html file with
 
 body
 ?php
 echo Printing with php;
 ?
 ?body
 
 and it works fine.
 
 When I take out the php code and put it inot a file pp.php, and I call that 
 file with my browser (localhost/pp.php), it works, too.
 
 But when I change the html code to:
 
 body
 script type=text/javascript src=pp.php/script
 /body
 
 I get a blank page. this is probably something really stupid, but I have 
 been wrecking my head for days now, and I can't figure it out. anybody has 
 an idea? 
 

Hello Bode,
You obviously purposefully asked your browser not to parse you php code. You 
are linking to a javascript instead of a php file. It's this simple; if you are 
create a .php file and u wish to incorporate it in your html code, you should 
use a function called include();. Simply try something like:

body
?php include(pp.php); ?
/body

Let me know what u get from that.

Alugo Abdulazeez
Serving you from Nigeria.
http://www.frangeovic.com

_
With Windows Live, you can organize, edit, and share your photos.
http://www.microsoft.com/middleeast/windows/windowslive/products/photo-gallery-edit.aspx

Re: [PHP] Beginner question

2009-08-25 Thread mike bode

Well, as I said: Beginner ...

I am actually trying to implement some html code that I found on the web, 
which uses php (see: 
http://www.dynamicdrive.com/dynamicindex4/php-photoalbum.htm). They use the 
method I tried to call a function php and then display a photo album. 
Well, that doesn't work. I am just getting a blank page when I follow their 
instructions. So I thought I try to follow the trail and see where it ends. 
But how do I do that? I was attempting to do so with the script that I 
posted, but apparently that doesn't work. So, how do I find out why  my 
installation does not process the html code that I have posted a link to 
above? How would I implement that on my web site?


Thanks.

Ashley Sheridan a...@ashleysheridan.co.uk wrote in message 
news:1251211648.2799.46.ca...@localhost...

On Mon, 2009-08-24 at 23:16 -0600, mike bode wrote:
I am trying to use PHP on my web site I am developing now. I have 
installed
Apache 2.2 and PHP 5.2. My problem is that I can execute PHP code 
embedded

in my HTML code, but I can't execute the same cose when I put it into a
separate .php file that i then call from within the html code. for 
example:


I have a html file with

body
?php
echo Printing with php;
?
?body

and it works fine.

When I take out the php code and put it inot a file pp.php, and I call 
that

file with my browser (localhost/pp.php), it works, too.

But when I change the html code to:

body
script type=text/javascript src=pp.php/script
/body

I get a blank page. this is probably something really stupid, but I have
been wrecking my head for days now, and I can't figure it out. anybody 
has

an idea?



Yes, this is not how you use PHP! PHP isn't embedded in HTML, it's
actually the other way round.

You should make the main page a .php page and from there you can include
the necessary HTML parts like so:

?php
include includes/header.html;

// body code here

include includes/footer.html;
?

Thanks,
Ash
http://www.ashleysheridan.co.uk






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



RE: [PHP] Beginner question

2009-08-25 Thread Arno Kuhl
-Original Message-
From: mike bode [mailto:mikebo...@hotmail.com]
Sent: 25 August 2009 07:16 AM
To: php-general@lists.php.net
Subject: [PHP] Beginner question

I am trying to use PHP on my web site I am developing now. I have installed
Apache 2.2 and PHP 5.2. My problem is that I can execute PHP code embedded
in my HTML code, but I can't execute the same cose when I put it into a
separate .php file that i then call from within the html code. for example:

I have a html file with

body
?php
echo Printing with php;
?
?body

and it works fine.

When I take out the php code and put it inot a file pp.php, and I call that
file with my browser (localhost/pp.php), it works, too.

But when I change the html code to:

body
script type=text/javascript src=pp.php/script /body

I get a blank page. this is probably something really stupid, but I have
been wrecking my head for days now, and I can't figure it out. anybody has
an idea?

--

I presume your html/php code is in a file with a .php extension? If not then
change the extension to php because most other webservers won't parse php
code in a html file. If you have a .php file you can mix html and php the
way you described, and you can put your php code between the ?php and ?
tags.

The php script you're trying to include in your html code with javascript
script type=text/javascript src=pp.php/script
would presumably echo out the javascript code that ends up in your html
page, but if you don't know php then you're trying to run before you can
walk.

If possible try to see what javascript code is being generated (echoed) by
the php script and put it in a normal .js file (e.g. pp.js) and then use it
like any other javascript file
script type=text/javascript src=pp.js/script
This isn't always possible because often php is used to decide what
javascript to output (otherwise why bother). If you have to use php to
generate your javascript code then start with small steps - try echoing some
simple js code in your pp.php (like an alert) just so you can see how it
works. Once you get that working you can move on to more useful things.


To illustrate, what's actually happening with the code you have at the
moment is this:

The browser parses the initial html code and finds
script type=text/javascript src=pp.php/script
And sends a request back to the server for pp.php

The server runs pp.php and send the output generated by the php script back
to the browser,
so effectively the browser ends up with
script type=text/javascriptPrinting with php/script

Obviously that isn't going to work. Hopefully you can now see what the
problem is and how to fix it.


Cheers
Arno





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



Re: [PHP] Beginner question

2009-08-25 Thread tedd

At 11:16 PM -0600 8/24/09, mike bode wrote:
I get a blank page. this is probably something really stupid, but I 
have been wrecking my head for days now, and I can't figure it out. 
anybody has an idea?


Mike:

Here's an idea -- try this:

http://sperling.com/examples/include-demo/

If you complete that (a hour or so, not days), you'll have a much 
better idea of what this is all about.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Beginner question

2009-08-25 Thread mike bode

Thanks.

I will surely do that.

In the meantime I have found out that it really is not a problem with the 
code. I uploaded the (non-functioning code) from my PC to a public web 
server, and lo and behold, the code works.

It thus appears that there is something wrong with my php-apache setup.

Now that's a whole other issue that I now need to try to solve. Any 
suggestions where to start?


Thanks.

tedd tedd.sperl...@gmail.com wrote in message 
news:p06240806c6b9e3571...@[192.168.1.102]...

At 11:16 PM -0600 8/24/09, mike bode wrote:
I get a blank page. this is probably something really stupid, but I have 
been wrecking my head for days now, and I can't figure it out. anybody has 
an idea?


Mike:

Here's an idea -- try this:

http://sperling.com/examples/include-demo/

If you complete that (a hour or so, not days), you'll have a much better 
idea of what this is all about.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com 



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



Re: [PHP] Beginner question

2009-08-25 Thread mike bode
I see. PHP runs on the server and cannot directly interact with my browser, 
only through Javascript. So I can use javascript to trigger a php script, 
which does something on the server, and returns something to javascript on 
my machine, which can then be used to do something on my browser.


However, as I just said in this thread, I found out that the code is 
actually working, just not on my machine. I uploaded the code to a public 
web server (www.bestrmvacation.com/album.htm, if you want to check it out), 
and it works there. But not on my computer. There must be something broken 
with my PHP or Apache Installation. However, when I run a PHP script that 
calls phpinfo(), it works fine. Any idea where this might go wrong?


BTW, I am using Expression Web to develop the web site. Could that have 
anything to do with it?


Thanks.

Arno Kuhl ak...@telkomsa.net wrote in message 
news:a6c65a0610f9485787e31f7161cb7...@point01...

-Original Message-
From: mike bode [mailto:mikebo...@hotmail.com]
Sent: 25 August 2009 07:16 AM
To: php-general@lists.php.net
Subject: [PHP] Beginner question

I am trying to use PHP on my web site I am developing now. I have 
installed

Apache 2.2 and PHP 5.2. My problem is that I can execute PHP code embedded
in my HTML code, but I can't execute the same cose when I put it into a
separate .php file that i then call from within the html code. for 
example:


I have a html file with

body
?php
echo Printing with php;
?
?body

and it works fine.

When I take out the php code and put it inot a file pp.php, and I call 
that

file with my browser (localhost/pp.php), it works, too.

But when I change the html code to:

body
script type=text/javascript src=pp.php/script /body

I get a blank page. this is probably something really stupid, but I have
been wrecking my head for days now, and I can't figure it out. anybody has
an idea?

--

I presume your html/php code is in a file with a .php extension? If not 
then
change the extension to php because most other webservers won't parse 
php

code in a html file. If you have a .php file you can mix html and php the
way you described, and you can put your php code between the ?php and ?
tags.

The php script you're trying to include in your html code with javascript
script type=text/javascript src=pp.php/script
would presumably echo out the javascript code that ends up in your html
page, but if you don't know php then you're trying to run before you can
walk.

If possible try to see what javascript code is being generated (echoed) by
the php script and put it in a normal .js file (e.g. pp.js) and then use 
it

like any other javascript file
script type=text/javascript src=pp.js/script
This isn't always possible because often php is used to decide what
javascript to output (otherwise why bother). If you have to use php to
generate your javascript code then start with small steps - try echoing 
some

simple js code in your pp.php (like an alert) just so you can see how it
works. Once you get that working you can move on to more useful things.


To illustrate, what's actually happening with the code you have at the
moment is this:

The browser parses the initial html code and finds
script type=text/javascript src=pp.php/script
And sends a request back to the server for pp.php

The server runs pp.php and send the output generated by the php script 
back

to the browser,
so effectively the browser ends up with
script type=text/javascriptPrinting with php/script

Obviously that isn't going to work. Hopefully you can now see what the
problem is and how to fix it.


Cheers
Arno







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



Re: [PHP] Beginner question

2009-08-25 Thread tedd

At 2:45 PM -0600 8/25/09, mike bode wrote:
I see. PHP runs on the server and cannot directly interact with my 
browser, only through Javascript.


Kind of.

PHP runs on the server and can create html, css, javascript et al. 
However, PHP will complete it's task before the browser see's 
anything. Once the browser see's the code, it's up to the browser to 
interpret and run html, css, and javascript.


If your html is a form (i.e., submit), or you have javascript 
running, then either of those can trigger a php script on the server 
to run which can repeat the process in generating new html, css, and 
javascript (if needed). Normally, javascript is not generated by PHP, 
but it can be.


Using javascript to trigger an event certainly works IF javascript is 
turned on by the user's browser. However, this is something that you 
have absolutely no control over. A user can turn javascript ON/OFF at 
their discretion. You see, many people turn javascript off because of 
security concerns -- and those concerns are not without foundation.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Beginner Question

2007-01-19 Thread Robert Cummings
On Fri, 2007-01-19 at 19:21 +0100, Delta Storm wrote:
 Hi,
 
 I have learned as lot about PHP but I still dont know how do they build 
 PHP based web sites.

Obviously you haven't learned enough ;)

 I need to build a complete PHP site with a lot of content and integrate 
 CSS,javaScript and a lot of other stuff (for the school)

Woohooo, a good way to learn, though hopefully you get the security
right the first time :)

 (Complete site for example. www.domain1.com/index.php or 
 www.domain2.co/about?set=p1)
 I want to know how are the sites built, do they build for each page a 
 PHP script or do they build just a couple of scripts and a database full 
 of content and just retrieve and delete,edit,show database information?

Depends on who builds it, what they use, and personal preference. For
instance most Drupal sites are mostly database driven. But other sites
may be file based. Some use a front end controller pattern so you access
a single page that determines what you see via the URL's parameters,
others use real files. Others use URL rewriting tricks via the web
server to make it the front end controller pattern look like real files.

 I know that when I see in the sites url php? that means that site has a 
 database, right...?

Nope, that generally means it's using PHP, but not always. Anyone can
set their webserver to invoke whatever server side language they want to
use regardless of file extension. Some common PHP extensions though are,

.php, .php3, .phtml, .html

 Either way I would be very gratefull if you could you give me a detailed 
 explanation of the process of building a PHP/MySQL site (I know to write 
 scripts in PHP so im not a total beginner).

You'll need a webserver, I recommend Apache:

http://httpd.apache.org/

You will probably want to install PHP as amodule for use by the
webserver. You should check out the PHP website, it explains how to set
things up:

http://www.php.net/manual/en/install.general.php

I suggest installing on a *nix system versus crappy Windows. But feel
free to use Windows if you're just a noobie.

You don't need a database to learn the basics, mostly you just need to
know how to set up the webserver, where to place your files, how to
retrieve form posts and URL parametets, and how to output HTML. The PHP
website is a goldmine of information. The comments can be quite helpful
also.

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



RE: [PHP] Beginner Question

2004-04-09 Thread jon roig
Doesn't the Apple Developer Tools disk have all that stuff?

http://developer.apple.com/tools/

-- jon

---
jon roig
web developer
email: [EMAIL PROTECTED]
phone: 888.230.7557

-Original Message-
From: rob [mailto:[EMAIL PROTECTED] 
Sent: Thursday, April 08, 2004 10:31 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Beginner Question


I am a newcomer to PHP and I am looking for an intsallation package
similar to to FoxPro for MAC OSX 10.2.(Ie intsall appache, MY SQL and
Latest version of PHP) Does anyone know where I may find one? Thanks RB

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


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.644 / Virus Database: 412 - Release Date: 3/26/2004
 
  

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.644 / Virus Database: 412 - Release Date: 3/26/2004
 

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



Re: [PHP] Beginner Question

2004-04-09 Thread Kris J. Hagel
On Thu, 2004-04-08 at 22:30, rob wrote:
 I am a newcomer to PHP and I am looking for an intsallation package similar
 to to FoxPro for MAC OSX 10.2.(Ie intsall appache, MY SQL and Latest version
 of PHP) Does anyone know where I may find one?
 Thanks RB

Try http://www.serverlogistics.com

They have packaged installers for Apache, MySQL and PHP with Preference
Panes you can drop in to control the Apache and MySQL processes if you
want them.

Kris

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



Re: [PHP] Beginner Question-Solution-packages

2004-04-09 Thread rob
On 10/4/04 1:37 AM, jon roig [EMAIL PROTECTED] wrote:

Thank you for your help! Php and mysql ship on MAC OSX servers but not on on
the normal machines.
Apple provides support for these two at
http://developer.apple.com/internet/opensource/osdb.html for help on MySQL
on MAC OSX including step by step instructions on how to install it.
Assistance with PHP is found at
http://developer.apple.com/internet/opensource/php.html including help on
how to install it.
I have not found integrated packages for Macs like FoxPro but the above
links will get you up and running.
Marc Linnage has a standalone installer for the latest release of PHP for
OSX at http://www.entropy.ch/software/macosx/php/- very easy to install for
beginners.
I had trouble installing MySQL(from MySQL.com) but found the server
logistics package a breeze at http://www.serverlogistics.com/mysql.php
Once again thks for pointing me to the developer section at Apple
RB

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



Re: [PHP] beginner question about while loops

2004-02-09 Thread Jochem Maas
Paul,

   the warning that John refers to does occur - whether you see it 
depends on the error reporting level, PHP will create the array for you 
 if you have not already initialized it but a warning will be generated 
in such cases. - errors that may not display on one machine might be 
visible on another due to differences in the error reporting level.

error reporting level is set in the php.ini file (it can also be set in 
your script see http://nl2.php.net/ini_set), you probably have a line in 
your php.ini that looks like:

error_reporting = E_ALL  ~E_WARNING  ~E_NOTICE

which means: log all errors except warning level and notice level errors
I recommend you try to set the error reporting level to:
error_reporting = E_ALL

in this way all errors are logged (and possibly displayed) - if you can 
write bug/error free code with error reporting set to E_ALL then you 
will have made a good start towards more professional/better coding 
practices.

there is another php.ini line:

display_errors = On

this line determines if errors are output to the browser window. for web 
development this should be definitely on. (productions server often have 
it Off for speed and 'niceness' reasons - i.e. not many users are 
interested in seeing PHP errors, for whatever reason!)

---

as a rule of thumb it is better to initialize variable before you use them.

e.g. $pictures = array();

otherwise, in your case, if no files are present in the directory (or 
none have a 'jpg' extension) referencing the $pictures array the while 
loop will cause another error.

---
Side Note:
for beginners often RTFM only leads to more confusion because the 
contents of many technical manuals often assume that the reader has 
knowledge which a beginner does not yet have. I don't feel that this is 
very much the case of the PHP manual - my feeling is that is very 
accessible. I recommend taking the time to read all of it - the parts 
you don't yet understand often become clear with continued reading. The 
time invested in reading the manual is quickly regained!

Paul Furman wrote:

OK thanks again for helping through the stumbling blocks... I'm rolling 
again now.

John W. Holmes wrote:

Just make sure $pictures is defined as an array before you try to push a
value onto it (even using the method you have now), otherwise you'll 
get a
warning.


It seems to be working fine this way without defining it as an array but 
I guess other languages would not accept that approach.

   while ($file = readdir($dh)){
if (strstr ($file, '.jpg')){
$pictures[] = $file;
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] beginner question about while loops

2004-02-09 Thread Paul Furman
Jochem Maas wrote:
Paul,

   the warning that John refers to does occur - whether you see it 
depends on the error reporting level, PHP will create the array for you 
 if you have not already initialized it but a warning will be generated 
in such cases. ...

error_reporting = E_ALL

...
display_errors = On

...
as a rule of thumb it is better to initialize variable before you use them.

e.g. $pictures = array();

otherwise, in your case, if no files are present in the directory (or 
none have a 'jpg' extension) referencing the $pictures array the while 
loop will cause another error.


Thanks for the advice. I do think the manual is pretty good and I'll 
spend more time with it. But... I do have error reporting set to all. I 
think they may have changed the behavior on newer versions of PHP. I 
have indeed experienced the non-existant array eerror you describe. Lots 
of debugging to do!

PS here's my results from a voracious weekend of coding:
http://hills.ccsf.edu/~pfurma02/index.php?SCREEN=ecards.php
Thanks for all your help!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] beginner question about while loops

2004-02-06 Thread Eric Gorr
At 11:41 AM -0800 2/6/04, Paul Furman wrote:
  while ($file = readdir($dh)){
  if (strstr ($file, '.jpg')){
  $pictures[] = $file;
  }
Spotted this problem when staring at your code.

Number of open braces: 2
Number of close braces: 1
You need to close off your while loop.

Should I set up a counter for loops $integer++ or if I'm going 
through something
You can if you like, but it is not necessary in this case.

the while function knows to just go through those and fills in array 
numbers accordingly?
The while function has nothing to do with it. Using the syntex 
$array[] simply adds an element onto the _end_ of the array and PHP 
picks the next logical, numerical index.

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


RE: [PHP] beginner question about while loops

2004-02-06 Thread Alex Hogan
You didn't close your loop;

while ($file = readdir($dh)){
if (strstr ($file, '.jpg')){
$pictures[] = $file;
}
#vardump ($pictures[]);
} = here
 ?

instead of;

while ($file = readdir($dh)){
if (strstr ($file, '.jpg')){
$pictures[] = $file;
}
#vardump ($pictures[]);
 ?

alex

 -Original Message-
 From: Paul Furman [mailto:[EMAIL PROTECTED]
 Sent: Friday, February 06, 2004 1:41 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] beginner question about while loops
 
 Totally ignorant need for clarification... Should I set up a counter for
 loops $integer++ or if I'm going through something, the while function
 knows to just go through those and fills in array numbers accordingly?
 
 Below is my project (while loop at the bottom):
 
 I'm getting unexpected $end on line 18 but the file only has 17 lines!
 
 ?php
if (isset ($_REQUEST ['IMGDIR'])){
$imagedir=$_REQUEST ['IMG_DIR'];
 } else {
$imagedir = PUB_DIR . '/grasses';
 #PUB_DIR coordinates my public htm location at home  school
 }
if (!(chdir ($imagedir))){
  print invalid directory;
  }
$fh=opendir($imagedir);
while ($file = readdir($dh)){
if (strstr ($file, '.jpg')){
$pictures[] = $file;
}
#vardump ($pictures[]);
 ?
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


** 
The contents of this e-mail and any files transmitted with it are 
confidential and intended solely for the use of the individual or 
entity to whom it is addressed.  The views stated herein do not 
necessarily represent the view of the company.  If you are not the 
intended recipient of this e-mail you may not copy, forward, 
disclose, or otherwise use it or any part of it in any form 
whatsoever.  If you have received this e-mail in error please 
e-mail the sender. 
** 




Re: [PHP] beginner question about while loops

2004-02-06 Thread Paul Furman
Eric Gorr wrote:

the while function knows to just go through those and fills in array 
numbers accordingly?


The while function has nothing to do with it. Using the syntax $array[] 
simply adds an element onto the _end_ of the array and PHP picks the 
next logical, numerical index.


OK thanks guys, I got the missing curly brace  some other messes.

So when assigning values to an array inside a loop, it knows to advance 
to the next but then if I want to print those out at the same time, it's 
complaining

  while ($file = readdir($fh)){
  if (strstr ($file, '.jpg')){
  $pictures[] = $file;
  #print $pictures[];  #Fatal error: Cannot use [] for reading
  }
  var_dump ($pictures[]); #Fatal error: Cannot use [] for reading
  }


This one works but complains about Undefined variable: pictures NULL 
array (but it dumps the contents of $pictures[]:

  while ($file = readdir($fh)){
  if (strstr ($file, '.jpg')){
  $pictures[] = $file;
  }
  var_dump ($pictures);
  }
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] beginner question about while loops

2004-02-06 Thread Rob Adams

Paul Furman [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Eric Gorr wrote:

[snip]


while ($file = readdir($fh)){
if (strstr ($file, '.jpg')){
$pictures[] = $file;
#print $pictures[];  #Fatal error: Cannot use [] for reading

Which element are you trying to print?  I'm guessing the current one, so
just use:
  print $file;

}
var_dump ($pictures[]); #Fatal error: Cannot use [] for reading
}



 This one works but complains about Undefined variable: pictures NULL
 array (but it dumps the contents of $pictures[]:

while ($file = readdir($fh)){
if (strstr ($file, '.jpg')){
$pictures[] = $file;
}
var_dump ($pictures);
}

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



RE: [PHP] beginner question about while loops

2004-02-06 Thread Shaunak Kashyap
1. Using [] creates a new array element. Hence the error. You can try this
piece of code inside the loop

[code]
if (strstr ($file, '.jpg')){

$refPictures =  $pictures[];

$refPictures = $file;
  print $refPictures;
}
[/code]

$refPictures holds a reference to the newly created element of the $pictures
array. Therefore, by assigning $file to $refPictures, $file is actually
getting assigned to the newly created element of the $pictures array. The
same logic applies in the print statement

2. Again, using [] in the var_dump indicates that you are trying to create a
new element of the $pictures array. If dumping the contents of the entire
array along with their data types and such is what you are trying to
achieve, the correct syntax is

[code]
var_dump($pictures);
[/code]

 -Original Message-
 From: Paul Furman [mailto:[EMAIL PROTECTED]
 Sent: Friday, February 06, 2004 3:09 PM
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] beginner question about while loops


 Eric Gorr wrote:
 
  the while function knows to just go through those and fills in array
  numbers accordingly?
 
 
  The while function has nothing to do with it. Using the syntax $array[]
  simply adds an element onto the _end_ of the array and PHP picks the
  next logical, numerical index.


 OK thanks guys, I got the missing curly brace  some other messes.

 So when assigning values to an array inside a loop, it knows to advance
 to the next but then if I want to print those out at the same time, it's
 complaining

while ($file = readdir($fh)){
if (strstr ($file, '.jpg')){
$pictures[] = $file;
#print $pictures[];  #Fatal error: Cannot use [] for reading
}
var_dump ($pictures[]); #Fatal error: Cannot use [] for reading
}



 This one works but complains about Undefined variable: pictures NULL
 array (but it dumps the contents of $pictures[]:

while ($file = readdir($fh)){
if (strstr ($file, '.jpg')){
$pictures[] = $file;
}
var_dump ($pictures);
}

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


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



Re: [PHP] beginner question about while loops

2004-02-06 Thread John W. Holmes

- Original Message - 
From: Paul Furman [EMAIL PROTECTED]

 Totally ignorant need for clarification... Should I set up a counter for
 loops $integer++ or if I'm going through something, the while function
 knows to just go through those and fills in array numbers accordingly?
[snip]
while ($file = readdir($dh)){
if (strstr ($file, '.jpg')){
$pictures[] = $file;
}

With this syntax, you do not need to keep an $integer variable for the array
key. When you use $array[] = something, it just assigns that value to the
next available numeric key.

while ($file = readdir($dh)){
if (strstr ($file, '.jpg')){
$pictures[$int++] = $file;
}

Would also be correct, if you wanted to keep the count yourself. You could
also use array_push().

Just make sure $pictures is defined as an array before you try to push a
value onto it (even using the method you have now), otherwise you'll get a
warning.

---John Holmes...

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



Re: [PHP] beginner question about while loops

2004-02-06 Thread Paul Furman
OK thanks again for helping through the stumbling blocks... I'm rolling 
again now.

John W. Holmes wrote:
Just make sure $pictures is defined as an array before you try to push a
value onto it (even using the method you have now), otherwise you'll get a
warning.
It seems to be working fine this way without defining it as an array but 
I guess other languages would not accept that approach.

   while ($file = readdir($dh)){
if (strstr ($file, '.jpg')){
$pictures[] = $file;
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] beginner question about while loops

2004-02-06 Thread John W. Holmes
From: Paul Furman [EMAIL PROTECTED]

 So when assigning values to an array inside a loop, it knows to advance
 to the next but then if I want to print those out at the same time, it's
 complaining

while ($file = readdir($fh)){
if (strstr ($file, '.jpg')){
$pictures[] = $file;
#print $pictures[];  #Fatal error: Cannot use [] for reading
}
var_dump ($pictures[]); #Fatal error: Cannot use [] for reading
}

Can't do that, like it says. You just assigned $file to $print.. so just
display the value of $file.

---John Holmes...

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



Re: [PHP] Beginner question : Removing spaces in forms

2002-12-13 Thread Hugh Danaher
you could start with something like:
$old_string=44 55 99 111;
$new_string=ereg_replace( ,,$old_string);
echo $new_string;
should display
445599111
There are other regular expression aids listed on the page at:
http://www.php.net/manual/en/function.ereg-replace.php
Hope this helps,
Hugh

- Original Message -
From: Andrew Wilson [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, December 12, 2002 7:19 PM
Subject: [PHP] Beginner question : Removing spaces in forms



 Hay guys i was wondering if there was a form parameter of something
 equivalent for input text boxes that when a user enters a number or series
 of numbers that it removes the spaces.
 If there is no alternative how would you go about solving this issue.

 Your help is appreciated.
 Thanks.


 Netway Networks Pty Ltd
 (T) 8920 8877
 (F) 8920 8866



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



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




Re: [PHP] Beginner question?

2001-12-21 Thread Michael Sims

At 01:59 AM 12/21/2001 -0500, jtjohnston wrote:
Michael,

$fp = fopen (./users.txt, r);
while (!feof ($fp)) {
  $buffer = fgets($fp, 4096);
  echo $buffer;
  }
fclose($fp);

Ok. But $buffer is not an array, is it? Why/what is 4096? What is !feof ?

Don't you have access to the WWW?  You need to follow the link I gave you 
and actually READ it.  Your first two questions are answered here:

http://www.php.net/manual/en/function.fgets.php

And your next one here:

http://www.php.net/manual/en/function.feof.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Beginner question?

2001-12-21 Thread Brian Rue

Can anyone show me how to split() each line and parse to see if $user
exists?

// get contents of a file into a string
$filename = ./users.txt;
$fd = fopen ($filename, r);
$contents = fread ($fd, filesize ($filename));
fclose ($fd);

// seperate the string into an array of lines
$linebreak = \n;
$lines = explode($linebreak,$contents);

// seperate each line into an array of words
for ($i=0;$icount($lines);$i++){
$words[$i]=explode( ,$lines[$i]);
}
- Original Message -
From: jtjohnston [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, December 20, 2001 10:59 PM
Subject: Re: [PHP] Beginner question?


Michael,

$fp = fopen (./users.txt, r);
while (!feof ($fp)) {
 $buffer = fgets($fp, 4096);
 echo $buffer;
 }
fclose($fp);

Ok. But $buffer is not an array, is it? Why/what is 4096? What is !feof ?

Can anyone show me how to split() each line and parse to see if $user
exists?

Here's what I'm upto. I want to use users.txt as a user:password text
database
file.
I want to read users.txt into an array.
I want to parse each line splitting for :

user:pass
john:help
michael:thanks

$fp = fopen (./users.txt, r);
while (!feof ($fp)) {
 $buffer = fgets($fp, 4096);
 echo $buffer;
 }
fclose($fp);

$user = john;
$num_fields = count($buffer);
for ($i = 0; $i  $num_fields; $i++)
{
if ?? = $user then echo ??
}

Can anyone show me how to split() each line and parse to see if $user
exists?


 ?php
 $fp = fopen (./info.txt, r);
 print $fp;
 fclose($fp);
 ?

 $fp is just a file pointer, not the actual contents of the file.  You need
 to use fgets() (or something similar) to actually get the contents out.
 http://www.php.net/manual/en/function.fgets.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Beginner question?

2001-12-20 Thread Martin Towell

?php

//$fp = fopen (C:/Program Files/localhost/info.txt, r);
//$fp = fopen (http://compcanlit.ca/;, r);
$fp = fopen (./info.txt, r);

while (!foef($fp))
{
  $line = fgets($fp, 1024);
  echo $line;
}

fclose($fp);
?

what you were doing was opening a file ready for reading and then printing
the pointer to the file, and not the file itself...

-Original Message-
From: jtjohnston [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 21, 2001 4:13 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Beginner question?


This seems newbie. So what am I doing wrong? I want to print the
contents of the file. I get resource id #1 instead. Do I need to add a
header or what?

?php

//$fp = fopen (C:/Program Files/localhost/info.txt, r);
//$fp = fopen (http://compcanlit.ca/;, r);
$fp = fopen (./info.txt, r);

print $fp;

fclose($fp);

?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



Re: [PHP] Beginner question?

2001-12-20 Thread Michael Sims

At 12:13 AM 12/21/2001 -0500, jtjohnston wrote:
This seems newbie. So what am I doing wrong? I want to print the
contents of the file. I get resource id #1 instead. Do I need to add a
header or what?

?php

//$fp = fopen (C:/Program Files/localhost/info.txt, r);
//$fp = fopen (http://compcanlit.ca/;, r);
$fp = fopen (./info.txt, r);

print $fp;

fclose($fp);

?

$fp is just a file pointer, not the actual contents of the file.  You need 
to use fgets() (or something similar) to actually get the contents out.

http://www.php.net/manual/en/function.fgets.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Beginner question?

2001-12-20 Thread jtjohnston

Michael,

$fp = fopen (./users.txt, r);
while (!feof ($fp)) {
 $buffer = fgets($fp, 4096);
 echo $buffer;
 }
fclose($fp);

Ok. But $buffer is not an array, is it? Why/what is 4096? What is !feof ?

Can anyone show me how to split() each line and parse to see if $user exists?

Here's what I'm upto. I want to use users.txt as a user:password text database
file.
I want to read users.txt into an array.
I want to parse each line splitting for :

user:pass
john:help
michael:thanks

$fp = fopen (./users.txt, r);
while (!feof ($fp)) {
 $buffer = fgets($fp, 4096);
 echo $buffer;
 }
fclose($fp);

$user = john;
$num_fields = count($buffer);
for ($i = 0; $i  $num_fields; $i++)
{
if ?? = $user then echo ??
}

Can anyone show me how to split() each line and parse to see if $user exists?


 ?php
 $fp = fopen (./info.txt, r);
 print $fp;
 fclose($fp);
 ?

 $fp is just a file pointer, not the actual contents of the file.  You need
 to use fgets() (or something similar) to actually get the contents out.
 http://www.php.net/manual/en/function.fgets.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Beginner question?

2001-12-20 Thread jtjohnston

:) Again why 1024? or 4096 or ... ?

 while (!foef($fp))
 {
   $line = fgets($fp, 1024);
   echo $line;
 }


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]