|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
php-general Digest 24 May 2006 13:55:34 -0000 Issue 4146
php-general-digest-help
lists.php.net
Date: Wed May 24 2006 - 08:55:34 CDT
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
php-general Digest 24 May 2006 13:55:34 -0000 Issue 4146
Topics (messages 236795 through 236819):
Re: Going through 2 arrays at once
236795 by: David Tulloh
236797 by: Pavleck, Jeremy D.
Re: PHP & SNMP
236796 by: Chris
Re: Can php convert doc to HTML?
236798 by: Dotan Cohen
236817 by: Finner, Doug
Re: Can a script run twice?
236799 by: Lester Caine
236803 by: Stut
236804 by: Robert Cummings
236811 by: Lester Caine
236818 by: tedd
Re: 3DES w/ openssl_{csr,pkey}_new ?
236800 by: Chris
236816 by: Brian A. Seklecki
Re: How to disable PHP's POST caching?
236801 by: Stut
Parse error: syntax error, unexpected ',' in
236802 by: Mark Sargent
236805 by: Stut
236806 by: Robin Vickery
236807 by: Chris
236808 by: Mark Sargent
captcha or other recommendations
236809 by: Angelo Zanetti
236810 by: Angelo Zanetti
236819 by: tedd
Serialize
236812 by: phplist.f2s.com
236813 by: Chris
236814 by: Andrei
236815 by: Robin Vickery
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscribe
lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscribe
lists.php.net
To post to the list, e-mail:
php-general
lists.php.net
----------------------------------------------------------------------
attached mail follows:
Pavleck, Jeremy D. wrote:
> how do I go through 2 arrays at
> once with different keys?
>
> for ( $i = 0; $i < sizeof($logicalDrive); $i++) {
> echo "$arrLogDrive[$i]<br />\n";
> }
>
> for (reset($logicalDrive); $i = key($logicalDrive); next($logicalDrive))
> {
> echo "$i: $logicalDrive[$i]<br />\n";
> }
The slight complication here is that you are iterating through an
indexed and an associative array. There are two easy solutions,
building on each of the above loops.
As you don't care about the key of the second array you can convert it
to an indexed array using array_values().
$logicalDrive_indexed = array_values($logicalDrive);
for($i=0; $i<min(sizeof($arrLogDrive), sizeof($logicalDrive)); $i++) {
echo $arrLogDrive[$i].": ".$logicalDrive[$i]."<br />\n";
}
Alternatively the next() function works for indexed arrays.
for(reset($arrLogDrive), reset($logicalDrive);
current($arrLogDrive)!==false && current($logicalDrive)!==false;
next($arrLogDrive), next($logicalDrive)) {
echo current($arrLogDrive).": ".current($logicalDrive)."<br />\n";
}
The second approach will have problems if either of the arrays contain
the value false. Personally I would use the first loop.
David
attached mail follows:
Thanks for all the replies guys, it really helped me pick up a few
things.
One I ended up doing was using array_combine, like so:
$d = array_combine($arrLogDrive, $logicalDrive);
print_r($d);
for (reset($d); $j = key($d); next($d)) {
echo "$j: $d[$j]<br />\n";
}
Now, while it works spot on for me, since no one suggested it I assume
I'm not using it in it's greatest capacity and will look at other
methods. But hey, at least it works, I'm happy about that!
-----Original Message-----
From: David Tulloh [mailto:david
tulloh.id.au]
Sent: Tuesday, May 23, 2006 9:56 PM
To: Pavleck, Jeremy D.
Cc: PHP LIST
Subject: Re: [PHP] Going through 2 arrays at once
Pavleck, Jeremy D. wrote:
> how do I go through 2 arrays at
> once with different keys?
>
> for ( $i = 0; $i < sizeof($logicalDrive); $i++) {
> echo "$arrLogDrive[$i]<br />\n"; }
>
> for (reset($logicalDrive); $i = key($logicalDrive);
> next($logicalDrive)) {
> echo "$i: $logicalDrive[$i]<br />\n"; }
The slight complication here is that you are iterating through an
indexed and an associative array. There are two easy solutions,
building on each of the above loops.
As you don't care about the key of the second array you can convert it
to an indexed array using array_values().
$logicalDrive_indexed = array_values($logicalDrive); for($i=0;
$i<min(sizeof($arrLogDrive), sizeof($logicalDrive)); $i++) {
echo $arrLogDrive[$i].": ".$logicalDrive[$i]."<br />\n"; }
Alternatively the next() function works for indexed arrays.
for(reset($arrLogDrive), reset($logicalDrive);
current($arrLogDrive)!==false && current($logicalDrive)!==false;
next($arrLogDrive), next($logicalDrive)) {
echo current($arrLogDrive).": ".current($logicalDrive)."<br />\n"; }
The second approach will have problems if either of the arrays contain
the value false. Personally I would use the first loop.
David
attached mail follows:
Pavleck, Jeremy D. wrote:
> Greetings,
> Seem to have a bit of a problem I can't figure out. I'm trying to query
> servers via SNMP with PHP's snmpget function. Everything seems to work
> fine, no problems at all - except I'd like the web page to print the
> string value instead of the numeric value (I.E. OK for the Compaq Drive
> Array vs 1).
>
> Now I've configured everything as best I can tell, and I have the page
> loading the appropriate MIB file (
> snmp_read_mib("/usr/local/share/snmp/mibs/CPQIDA.MIB")).
>
> Running it from the terminal via 'php mypage.php' returns all the
> correct values, I see "Ok", instead of "1". But accessing it via the web
> produces nothing - no output. It doesn't matter how I set the get, I've
> tried varying it with "CPQIDA-MIB::cpqDaCntlrBoardStatus.0",
> "cpqDaCntlrBoardStatus.0",
> ".iso.org.dod.internet.private.enterprises.compaq.cpqDriveArray.cpqDaCom
> ponent.cpqDaCntlr.cpqDaCntlrTable.cpqDaCntlrEntry.cpqDaCntlrBoardStatus.
> 0" - all work fine running it via the terminal, but not via the web
> page.
Does the webpage show anything at all? Sounds like you have a fatal error..
Does the web php version have snmp support? Check with a phpinfo page.
--
Postgresql & php tutorials
http://www.designmagick.com/
attached mail follows:
On 5/24/06, Martin Alterisio <malterisio777
gmail.com> wrote:
> 2006/5/23, Jochem Maas <jochem
iamjochem.com>:
>
> > my 2cents ....
> >
> > Martin Alterisio wrote:
> > > 2006/5/23, Dotan Cohen <dotancohen
gmail.com>:
> > >
> > >>
> > >> On 5/23/06, Martin Alterisio < malterisio777
gmail.com> wrote:
> > >> >
> > >> > If that's the case, why don't you just use the "export as web page"
> or
> > >> "save
> > >> > as web page" tools of MS Word (if you don't have it anymore you can
> as
> > >> > someone who still has it, or I think OpenOffice also has a similar
> > >> tool).
> > >> >
> > >>
> > >> Because there are 200 of them.
> > >>
> > >> Dotan Cohen
> > >> http://what-is-what.com
> > >> 323
> > >>
> > >
> > >
> > > Open file, choose file, save as web page, close file ~ 2 minutes
> > > 200 files * 2 minutes = 400 minutes ~ 7 hours
> > > How much hours have you wasted looking for a php script?
> >
> > even if it takes him 14 hours to find a script and get it working
> > he will have:
> >
> > a, learnt quite abit about php'ing/html/etc
> > b, have the basis for a tool that can convert any future .doc
> > files that he finds/get thrown at him.
> >
> > Martin the suggestion you give sucks because it doesn't empower,
> > it leaves Dotan with a sore wrist and no gain in knowledge...
> >
> > maybe it's good advice for 'noobs' on an Office mailing
> > but this is a lsit about programming (sure it's php and plenty of IT
> > related people consider us phpers to be the pretty much the lowest form
> > of programmer - well not as low as VBscripters ;-) - anyone reading,
> posting
> > here, I would hope, aspires to a little more than PHB's secretary with
> > regards to their IT skills.
>
>
> You're completely right about that. Maybe living too much at the edge of the
> deadline has turned me into boring freak (most probably). I have to take
> this way of thinking out my mind.
>
> > >
> > > Anyway, I understand... it's a pain in the ass. Whay you're doing wrong
> is:
> > > you have turned your solution into a problem and forgot what the real
> > > problem was.
> >
> > this assumes there is a 'problem' - maybe Dotan is driven more or less
> > by a desire to see if he can do it rather than being up against some
> deadline
> > or having his boss breathing down his neck waiting for a result?
> >
>
> I disagree. There is always a problem, the kind of problem you're referring
> to is "I'm lacking this knowledge, or I want to know how to do X", in his
> case X would be "converting word docs to html with a php script".
>
> My first impression was that this was his problem, but deducing from what he
> explained after, I'm certain this isn't the problem he wants to solve, but
> rather a solution he came up but is unable to put into practice.
>
> I think this time PHP is not the solution. A shell script interacting with a
> third party tool, or a C program interacting with a third party library will
> be a much more appropiate solution.
>
Jochem, Martin,
I had considered the prospect of converting the documents one by one.
As Jochem had mentioned, time is not the only factor- I need a method,
not a solution. Even if there were 20 instead of two hunderd it would
be worth my while to learn to deal with them in an automated fashion.
I do agree that a bash script or C would be better suited to this. Too
bad I don't know either language. I am not in CS, I am in mechanical
engineering, but I am willing to learn. However, sometimes solutions
come before learning, so I decided to try a language that I at least
have a handle on. In any case, just as php has Simple XML functions
and a thousand other time-savers, I had hope that there would already
be a function or class that solves my problem.
Thanks, guys. I will check out wvware and see where it leads me. I
appreciate the advise!
Dotan Cohen
http://technology-sleuth.com
02
attached mail follows:
On 5/23/06, Martin Alterisio <malterisio777
gmail.com> wrote:
>
> If that's the case, why don't you just use the "export as web page" or
> "save as web page" tools of MS Word (if you don't have it anymore you
> can as someone who still has it, or I think OpenOffice also has a
similar tool).
>
> Because there are 200 of them.
>
> Dotan Cohen
Unless you want to do them one at a time, you'll need to write code.
Unless this is something that you need to do a lot, why not write the
code using OOo's programming language? Seems like all the appropriate
hooks should be there to pull in each Word doc, push it off as HTML, and
repeat for all the docs. I haven't worked with OOo for programming, but
it might be worth a look. Hit the OOo site and see what their forums
have to offer.
Doug
_______________________________________________________________________
This e-mail message has been sent by Kollsman, Inc. and is for the use
of the intended recipients only. The message may contain privileged
or confidential information. If you are not the intended recipient
you are hereby notified that any use, distribution or copying of
this communication is strictly prohibited, and you are requested to
delete the e-mail and any attachments and notify the sender immediately.
attached mail follows:
Robert Cummings wrote:
> These are called race conditions for a reason. They are racing against
> all kinds of things. Network latency, filesystem, processor, etc etc.
One site has take down it's Cisco backbone and replaced it with simple
hubs. Problems disappeared overnight! ( That was not just my problems )
> Any one of these thigns can slow down one thread just long enough for a
> newer thread to grab the session data before the older thread saves it.
> Then the newer thread happily uses the stale session and voila duplicate
> input. If you absolutely, definitely, for sure want to prevent this...
> use some kind of locking mechanism. I'd suggest locking the table that
> manages the form submission unique IDs until you've checked and, if
> necessary, updated it. There's a reason pages load sequentially in
> multiple frames when using PHP sessions... it's because PHP uses
> locking. Are you using PHP native sessions or your own home cooked
> system? Are sessions even activated? Did the user disabled sessions? Why
> am I teaching you second year comp sci? :)
>
> http://en.wikipedia.org/wiki/Race_condition
The double click 'problem' was a sideline to the original problem, which
I found while trying to track things. The original problem *IS* that PHP
can run two copies of a script in parallel and the second copy does NOT
see the 'locking' in place on the first copy. I had always thought that
PHP was sequential, but I'm not so sure now.
I've put in a trap for the double click ( and yes it *IS* browser
dependent ) and that works fine, but we will have to see if it makes any
difference to the original 'race' problem :(
--
Lester Caine - G8HFL
-----------------------------
L.S.Caine Electronic Services - http://home.lsces.co.uk
Model Engineers Digital Workshop -
http://home.lsces.co.uk/ModelEngineersDigitalWorkshop/
Treasurer - Firebird Foundation Inc. - http://www.firebirdsql.org/index.php
attached mail follows:
Lester Caine wrote:
> The double click 'problem' was a sideline to the original problem, which
> I found while trying to track things. The original problem *IS* that PHP
> can run two copies of a script in parallel and the second copy does NOT
> see the 'locking' in place on the first copy. I had always thought that
> PHP was sequential, but I'm not so sure now.
>
> I've put in a trap for the double click ( and yes it *IS* browser
> dependent ) and that works fine, but we will have to see if it makes any
> difference to the original 'race' problem :(
PHP is not 'sequential' and I have no idea where you got that
impression. If the browser puts in a request to the server, the server
will execute that request as soon as sufficient resources are free to do
so. PHP does not 'lock' the session between requests. This is a problem
being found by people trying AJAX with a session. Consider this sequence...
1) User hits your button (ooh-err)
2) PHP starts processing the script and runs session_start() which loads
the session data
3) User hits your button again
4) PHP starts processing the script a second time before the first run
has finished, and loads the session data again for this new request
5) The execution started in 2) ends and commits the session data back to
the session store
6) The execution started in 4) ends and commits the session data back to
the session store
There are 2 different issues here. First is that the second run will not
get any changes made in the first run. Second is that any changes made
in the first run will be lost when the second run commits the session to
the store. This is a fact of the stateless nature of HTTP and you need
to plumb around it. There are various ways you can do this. I'm the
first to admit that I haven't found an ideal solution yet, but methods
I've used in the past have been...
* Before start_session() check a directory for the existence of a file
named after the session id. If it doesn't exist call start_session() and
touch the lock file. Delete the lock file at the end of the request
(ideally using register_shutdown_function).
* Use shared memory to store an array of session ids that are locked.
Neither of these were ideal because there was a race condition where two
requests could check the lock at the same time and then both lock it.
Now that I come to think about it again it may be possible to write a
custom session handler that blocks reading of session data that's been
locked until it's either unlocked or a timeout passes. You'd have to try
that to see if it's possible - I'm not sure how the internals of
session_start() work.
Hope that early morning ramble helps you out.
-Stut
attached mail follows:
On Wed, 2006-05-24 at 01:45, Lester Caine wrote:
>
> The double click 'problem' was a sideline to the original problem, which
> I found while trying to track things. The original problem *IS* that PHP
> can run two copies of a script in parallel and the second copy does NOT
> see the 'locking' in place on the first copy. I had always thought that
> PHP was sequential, but I'm not so sure now.
But PHP doesn't run anything... the webserver passes the request to PHP,
and so if the webserver can process requests in parallel then the race
is on.
As for th elocking... it depends on how the locking is being done. Out
of curiosity, is session data being written to a network filesystem?
because all bets are off for network filesystems when trying to perform
locking on the files (and I think that's how PHP achieves session
locking).
> I've put in a trap for the double click ( and yes it *IS* browser
> dependent ) and that works fine, but we will have to see if it makes any
> difference to the original 'race' problem :(
Good luck :)
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. |
`------------------------------------------------------------'
attached mail follows:
Robert Cummings wrote:
>>I've put in a trap for the double click ( and yes it *IS* browser
>>dependent ) and that works fine, but we will have to see if it makes any
>>difference to the original 'race' problem :(
>
> Good luck :)
Actually the main problem was I was not updating the _SESSION variable
soon enough, so the second 'click' was still seeing the original value.
Now I set it with a dummy value (-1) until I can get the real value,
which requires a pass through the database, and the original logic seems
to be working fine - second string gets kicked out like it should.
--
Lester Caine - G8HFL
-----------------------------
L.S.Caine Electronic Services - http://home.lsces.co.uk
Model Engineers Digital Workshop -
http://home.lsces.co.uk/ModelEngineersDigitalWorkshop/
Treasurer - Firebird Foundation Inc. - http://www.firebirdsql.org/index.php
attached mail follows:
At 7:19 AM +0100 5/24/06, Stut wrote:
>PHP is not 'sequential' and I have no idea where you got that
>impression. If the browser puts in a request to the server, the
>server will execute that request as soon as sufficient resources are
>free to do so. PHP does not 'lock' the session between requests.
>This is a problem being found by people trying AJAX with a session.
>Consider this sequence...
>
>1) User hits your button (ooh-err)
>2) PHP starts processing the script and runs session_start() which
>loads the session data
>3) User hits your button again
>4) PHP starts processing the script a second time before the first
>run has finished, and loads the session data again for this new
>request
>5) The execution started in 2) ends and commits the session data
>back to the session store
>6) The execution started in 4) ends and commits the session data
>back to the session store
Nice explanation.
Ajax people are finding this happening w/o sessions.
Back to the posters problem, which is duplicate dB entries caused by
double clicking.
Apparently the problem isn't solvable by using tokens, sessions,
locking, and such. So why not just check the dB to see if the current
record has already been entered? If so, don't do it again.
Isn't this a solution? Or is there something here that I'm not understanding?
tedd
--
------------------------------------------------------------------------------------
http://sperling.com http://ancientstones.com http://earthstones.com
attached mail follows:
Brian A. Seklecki wrote:
>
> Does anyone know how to specify the encryption cipher used in this
> funciton as documented in OpenSSL's genrsa(1)?
>
> Why isn't the encryption method a value in [array configargs] ?
>
> -des|-des3|-idea
> These options encrypt the private key with the DES, triple DES,
> or
> the IDEA ciphers respectively before outputting it. If none of
> these options is specified no encryption is used.
>
> Or is the encryption method a value that can be specified in config=>
> and req_extensions=> ?
>
> Right now generated private keys look like:
>
> -----BEGIN RSA PRIVATE KEY-----
> Proc-Type: 4,ENCRYPTED
> DEK-Info: DES-EDE3-CBC,FA81C573DFD21B7D
>
>
> Which is 3DES, but some systems support AES, IDEA, Blowfish, Twofish, It
> depends on the OpenSSL config.
>
> Idea?
Read the documentation?
Took me about 30 seconds to find this page:
http://www.php.net/manual/en/function.openssl-csr-new.php
Where it says:
under "private_key_type"
Specifies the type of private key to create. This can be one of
OPENSSL_KEYTYPE_DSA, OPENSSL_KEYTYPE_DH or OPENSSL_KEYTYPE_RSA. The
default value is OPENSSL_KEYTYPE_RSA which is currently the only
supported key type.
So you can't use any other type.
--
Postgresql & php tutorials
http://www.designmagick.com/
attached mail follows:
RSA and DSA are different types of key formats. They do not imply
protecting the private keywith an encryption algorithm.
If you look at gendsa(1) or genrsa(1), you will see that passphrase
protection is optional to both, and that there a good many choices.
default_md is actually something from ca(1), it's the crypto signature
algorithm for public keys / certificates, and really doesn't apply to
private keys.
I'll just look at the source code when I get to the office.
~BAS
On Wed, 2006-05-24 at 01:54, Chris wrote:
> Brian A. Seklecki wrote:
> >
> > Does anyone know how to specify the encryption cipher used in this
> > funciton as documented in OpenSSL's genrsa(1)?
> >
> > Why isn't the encryption method a value in [array configargs] ?
> >
> > -des|-des3|-idea
> > These options encrypt the private key with the DES, triple DES,
> > or
> > the IDEA ciphers respectively before outputting it. If none of
> > these options is specified no encryption is used.
> >
> > Or is the encryption method a value that can be specified in config=>
> > and req_extensions=> ?
> >
> > Right now generated private keys look like:
> >
> > -----BEGIN RSA PRIVATE KEY-----
> > Proc-Type: 4,ENCRYPTED
> > DEK-Info: DES-EDE3-CBC,FA81C573DFD21B7D
> >
> >
> > Which is 3DES, but some systems support AES, IDEA, Blowfish, Twofish, It
> > depends on the OpenSSL config.
> >
> > Idea?
>
> Read the documentation?
>
> Took me about 30 seconds to find this page:
>
> http://www.php.net/manual/en/function.openssl-csr-new.php
>
> Where it says:
>
> under "private_key_type"
>
> Specifies the type of private key to create. This can be one of
> OPENSSL_KEYTYPE_DSA, OPENSSL_KEYTYPE_DH or OPENSSL_KEYTYPE_RSA. The
> default value is OPENSSL_KEYTYPE_RSA which is currently the only
> supported key type.
>
> So you can't use any other type.
attached mail follows:
Adam Zey wrote:
> Tunelling arbitrary TCP packets. Similar idea to SSH port forwarding,
> except tunneling over HTTP instead of SSH. A good example might be
> encapsulating an IRC (or telnet, or pop3, or ssh, etc) connection inside
> of an HTTP connection such that incomming IRC traffic goes over a GET to
> the client, and outgoing IRC traffic goes over a POST request.
>
> So, the traffic is bounced:
>
> [mIRC] ---> [client.php] -----internet-----> [apache ---> server.php]
> -----internet-----> [irc server]
>
> And the same in reverse. The connection between client.php and
> server.php is taking the IRC traffic and encapsulating it inside an HTTP
> connection, where it is unpacked by server.php before being sent on to
> the final destination. The idea is to get TCP tunneling working, once
> you do that you can rely on other programs to use that TCP tunnel for
> more complex things, like SOCKS.
You're trying to get a square peg through a round hole. The HTTP
protocol was not designed to do anything like this, so the standard
implementation by most web servers and PHP does not allow what you are
trying to do.
I'm curious about your 'lots of POSTs' solution. How are you keeping the
connection open on the server-side? It's certainly not possible to
maintain that connection between requests without using a process
outside the web server that maintains the connections. I've implemented
a system in the past to proxy IRC, MSN and AIM connections in this way,
but it only worked because the requests that came into PHP got passed to
this other process which held all the connections and managed the
traffic. And yes, it did generate a huge amount of traffic even when it
wasn't doing anything due to the need to poll the server for new
incoming messages.
This demonstrates a point at which you need to reconsider whether a
shared hosting environment (which I assume you're using given the
restrictions you've mentioned) is enough for your purposes. If you had a
dedicated server you could add another IP and run a custom server on it
that would be capable of doing exactly what you want. In fact there are
lots of nice free proxies that will happily sit on port 80. However,
it's worth nothing that a lot of firewalls block traffic that doesn't
look like HTTP, in which case you'll need to use SSL on port 443 to get
past those checks.
Anyways, long story (sorry) short, your square peg won't go in the round
hole without serious modification. Hope that helps.
-Stut
attached mail follows:
Hi All,
this code,
<?php
$flavour[] = "blue raspberry";
$flavour[] = "root beer";
$flavour[] = "pineapple";
sort($flavour);
print_r($flavour);
echo "<br>";
echo "My favourite flavours are:<br>";
foreach ($flavour as $currentValue) {
//these lines will execute as long as there is a value in $flavour
echo $currentValue "<br>\n";
}
?>
gives this,
*Parse error*: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING,
expecting ',' or ';' in */usr/local/apache2/htdocs/sorting.php* on line *18
*
and adding a , to this line,
foreach ($flavour, as $currentValue) {
gives this error,
*Parse error*: syntax error, unexpected ',' in
*/usr/local/apache2/htdocs/sorting.php* on line *16*
The code in the book I'm following has the , in that line. Can anyone
tell me what I'm doing wrong? Cheers.
Mark Sargent.
attached mail follows:
Mark Sargent wrote:
> Hi All,
>
> this code,
>
> <?php
> $flavour[] = "blue raspberry";
> $flavour[] = "root beer";
> $flavour[] = "pineapple";
> sort($flavour);
> print_r($flavour);
> echo "<br>";
> echo "My favourite flavours are:<br>";
> foreach ($flavour as $currentValue) {
> //these lines will execute as long as there is a value in $flavour
> echo $currentValue "<br>\n";
> }
> ?>
>
>
> gives this,
>
> *Parse error*: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING,
> expecting ',' or ';' in */usr/local/apache2/htdocs/sorting.php* on line *18
The echo in the foreach loop has no concatenation operator.
echo $currentValue "<br>\n";
should be
echo $currentValue."<br>\n";
> and adding a , to this line,
>
> foreach ($flavour, as $currentValue) {
>
> gives this error,
>
> *Parse error*: syntax error, unexpected ',' in
> */usr/local/apache2/htdocs/sorting.php* on line *16*
>
> The code in the book I'm following has the , in that line. Can anyone
> tell me what I'm doing wrong? Cheers.
If the code in the book you're reading really has a , in the foreach
line I suggest you throw it away and find another book, because that's
not valid PHP.
-Stut
attached mail follows:
On 24/05/06, Mark Sargent <powderkeg
snow.email.ne.jp> wrote:
> Hi All,
>
> this code,
>
> <?php
> $flavour[] = "blue raspberry";
> $flavour[] = "root beer";
> $flavour[] = "pineapple";
> sort($flavour);
> print_r($flavour);
> echo "<br>";
> echo "My favourite flavours are:<br>";
> foreach ($flavour as $currentValue) {
> //these lines will execute as long as there is a value in $flavour
> echo $currentValue "<br>\n";
> }
> ?>
>
>
> gives this,
>
> *Parse error*: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING,
> expecting ',' or ';' in */usr/local/apache2/htdocs/sorting.php* on line *18
>
> *
> and adding a , to this line,
>
> foreach ($flavour, as $currentValue) {
No, you were right the first time. No comma is required there.
Line 18 is the line with the echo statement on it. The items you want
to echo should be separated by commas:
So it should be:
echo $currentValue, "<br>\n";
-robin
attached mail follows:
Mark Sargent wrote:
> Hi All,
>
> this code,
>
> <?php
> $flavour[] = "blue raspberry";
> $flavour[] = "root beer";
> $flavour[] = "pineapple";
> sort($flavour);
> print_r($flavour);
> echo "<br>";
> echo "My favourite flavours are:<br>";
> foreach ($flavour as $currentValue) {
> //these lines will execute as long as there is a value in $flavour
> echo $currentValue "<br>\n";
> }
> ?>
>
>
> gives this,
>
> *Parse error*: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING,
> expecting ',' or ';' in */usr/local/apache2/htdocs/sorting.php* on line *18
>
> *
> and adding a , to this line,
>
> foreach ($flavour, as $currentValue) {
>
> gives this error,
>
> *Parse error*: syntax error, unexpected ',' in
> */usr/local/apache2/htdocs/sorting.php* on line *16*
Since there aren't actually 18 lines this isn't the real code..
The problem is here:
echo $currentValue "<br>\n";
it should be
echo $currentValue . "<br>\n";
or
echo $currentValue , "<br>\n";
--
Postgresql & php tutorials
http://www.designmagick.com/
attached mail follows:
Chris wrote:
> Since there aren't actually 18 lines this isn't the real code..
true, as I only posted the php code
>
> The problem is here:
>
> echo $currentValue "<br>\n";
>
> it should be
>
> echo $currentValue . "<br>\n";
>
> or
>
> echo $currentValue , "<br>\n";
>
thanx to all. The book is Beginning PHP, Apache, MySQL, Web Development
and it seems to only be a typo on that page(section) as the next page
shows similar code using the right syntax. I just didn't notice it till
after I posted. Cheers.
Mark Sargent
attached mail follows:
Hi all.
I've been playing with captcha for one of my sites. It works well but have had a few issues integrating it into the site and sometimes it appears not to work/show the textfield and graphic.
Anyway are there any other suggestions for something with similiar functionality as captcha and what are your experiences with these code bases?
TIA
--
Angelo Zanetti
Z Logic
www.zlogic.co.za
[c] +27 72 441 3355
[t] +27 21 469 1052
[f] +27 86 681 5885
attached mail follows:
Angelo Zanetti wrote:
> Hi all.
>
> I've been playing with captcha for one of my sites. It works well but
> have had a few issues integrating it into the site and sometimes it
> appears not to work/show the textfield and graphic.
>
> Anyway are there any other suggestions for something with similiar
> functionality as captcha and what are your experiences with these code
> bases?
>
> TIA
oh Im using the captcha from freshmeat...
attached mail follows:
>Hi all.
>
>I've been playing with captcha for one of my sites. It works well
>but have had a few issues integrating it into the site and sometimes
>it appears not to work/show the textfield and graphic.
>
>Anyway are there any other suggestions for something with similiar
>functionality as captcha and what are your experiences with these
>code bases?
>
>TIA
>--
>
>Angelo Zanetti
>Z Logic
Angelo:
Read this:
http://www.access-matters.com/2005/05/22/quiz-115-did-a-captcha-catch-ya/
While not prefect by any means (i.e., blind can't see it), you may
want to review my "click the circle" solution:
http://xn--ovg.com/captcha
If you want the code, I'll provide -- BUT -- try to find another way.
tedd
--
------------------------------------------------------------------------------------
http://sperling.com http://ancientstones.com http://earthstones.com
attached mail follows:
Hi,
Is a serialized array a "safe" string to insert into a mysql text field? Or is a
function such as mysql_real_escape_string always needed?
regards
Simon.
attached mail follows:
On 5/24/06, phplist
f2s.com <phplist
f2s.com> wrote:
> Hi,
>
> Is a serialized array a "safe" string to insert into a mysql text field? Or is a
> function such as mysql_real_escape_string always needed?
*Always* escape your data.
What if your array contains a quote?
--
Postgresql & php tutorials
http://www.designmagick.com/
attached mail follows:
It's not safe... if the array contains strings which contain ' or "
might screw your query... it's safe to escape the string result from
serialize...
Andy
phplist
f2s.com wrote:
> Hi,
>
> Is a serialized array a "safe" string to insert into a mysql text field? Or is a
> function such as mysql_real_escape_string always needed?
>
> regards
> Simon.
>
attached mail follows:
On 24/05/06, phplist
f2s.com <phplist
f2s.com> wrote:
> Hi,
>
> Is a serialized array a "safe" string to insert into a mysql text field? Or is a
> function such as mysql_real_escape_string always needed?
No, it's not at all a safe string to insert into a mysql text field.
mysql_real_escap_string() is needed.
-robin
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]