Re: [PHP] Re: strcmp() versus ==
2009/3/17 Shawn McKenzie nos...@mckenzies.net: Shawn McKenzie wrote: Paul M Foster wrote: I had never completely read over the rules with regard to comparisons in PHP, and was recently alarmed to find that $str1 == $str2 might not compare the way I thought they would. Is it common practice among PHP coders to use strcmp() instead of == in making string comparisons? Or am I missing/misreading something? Paul I would use $str1 === $str2 if you want to make sure they are both strings and both the same value. Since PHP is loosely typed, 0 == 0 is true however 0 === 0 is false. If you want to force a string comparison you can also use: (string)$str1 == (string)$str2 -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php AFAIK strcmp and strncmp are faster. At least for the second i remember seeing benchmarks that proved that. -- Alpar Torok -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Fork and zombies
Waynn Lue wrote: Here's pseudo code for what I'm trying to do: foreach ($things as $thing) { info = getInfo($thing); // uses a db connection makeApiCall(info); } makeApiCall(info) { $pid = pcntl_fork(); if ($pid == -1) { die(could not fork); } else if ($pid) { // parent, return the child pid echo child pid $pid\n; return; } else { // do some api calls exit; } } But after I spawn off the process, getInfo($thing) errors out sometime later on with an invalid query error, because I think the db connection is gone. I thought adding exit in the child process would be enough, but that doesn't seem to work, I still get the same error. Why would the child process affect the query in the parent process, especially if I exit in the child process? First things first - I would add a pcntl_wait like this: foreach ($things as $thing) { info = getInfo($thing); // uses a db connection makeApiCall(info); switch( $p=pcntl_wait( $stat, WNOHANG ) ) { case -1: echo some sort of error in pcntl_wait()\n; break; case 0: break; default: echo child $p finished\n; } } Second, it sounds like you're expecting to reuse your database connection from getInfo() in the child you're forking in makeAPIcall()? I don't think that really works - I think you need a new connection per child. /Per -- Per Jessen, Zürich (3.9°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: strcmp() versus ==
On Tue, 2009-03-17 at 08:09 +0200, Alpár Török wrote: 2009/3/17 Shawn McKenzie nos...@mckenzies.net: Shawn McKenzie wrote: Paul M Foster wrote: I had never completely read over the rules with regard to comparisons in PHP, and was recently alarmed to find that $str1 == $str2 might not compare the way I thought they would. Is it common practice among PHP coders to use strcmp() instead of == in making string comparisons? Or am I missing/misreading something? Paul I would use $str1 === $str2 if you want to make sure they are both strings and both the same value. Since PHP is loosely typed, 0 == 0 is true however 0 === 0 is false. If you want to force a string comparison you can also use: (string)$str1 == (string)$str2 -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php AFAIK strcmp and strncmp are faster. At least for the second i remember seeing benchmarks that proved that. Then you must have seen a bad benchmark. strncmp() has specific purposes and so does strcmp() where you would choose it instead of == or ===. But with respect to speed, if all you want to know is whether two strings are the same then == or === will be faster since they are operators and do not have the same overhead as a function call. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Fork and zombies
Here's pseudo code for what I'm trying to do: foreach ($things as $thing) { info = getInfo($thing); // uses a db connection makeApiCall(info); } makeApiCall(info) { $pid = pcntl_fork(); if ($pid == -1) { die(could not fork); } else if ($pid) { // parent, return the child pid echo child pid $pid\n; return; } else { // do some api calls exit; } } But after I spawn off the process, getInfo($thing) errors out sometime later on with an invalid query error, because I think the db connection is gone. I thought adding exit in the child process would be enough, but that doesn't seem to work, I still get the same error. Why would the child process affect the query in the parent process, especially if I exit in the child process? First things first - I would add a pcntl_wait like this: foreach ($things as $thing) { info = getInfo($thing); // uses a db connection makeApiCall(info); switch( $p=pcntl_wait( $stat, WNOHANG ) ) { case -1: echo some sort of error in pcntl_wait()\n; break; case 0: break; default: echo child $p finished\n; } } I actually tried this in the meantime: $pid = pcntl_fork(); if ($pid == -1) { die(could not fork); } else if ($pid) { // parent, return the child pid echo child pid $pid waiting\n; pcntl_waitpid($pid, $status); if (pcntl_wifexited($status)) { echo finished [$status] waiting\n; return; } else { echo ERROR\n; } But it still has the same problem, and I'm also trying to avoid pcntl_wait or pcntl_waitpid at all because I still want to do it asynchronously. I even tried rewriting it do return $pid in the parent thread, and then aggregate them at the calling function level, and then loop through them all with pcntl_waitpid, but that didn't work either. Second, it sounds like you're expecting to reuse your database connection from getInfo() in the child you're forking in makeAPIcall()? I don't think that really works - I think you need a new connection per child. Oh, in this case, I don't do anything with the database at all in the child thread. I was worried there would be some errors there so I actually commented out all db accesses in the child thread, but it still somehow closes the parent's db connection (or at least causes the query not to work, somehow).
Re: [PHP] Fork and zombies
Waynn Lue wrote: I actually tried this in the meantime: $pid = pcntl_fork(); if ($pid == -1) { die(could not fork); } else if ($pid) { // parent, return the child pid echo child pid $pid waiting\n; pcntl_waitpid($pid, $status); if (pcntl_wifexited($status)) { echo finished [$status] waiting\n; return; } else { echo ERROR\n; } I think your waitpid() is in the wrong place, and at least you need use WNOHANG - unless you specifically want to wait for each child to finish before starting another one. But it still has the same problem, and I'm also trying to avoid pcntl_wait or pcntl_waitpid at all because I still want to do it asynchronously. pcntl_wait(WNOHANG) will make everything work asynchronously. /Per -- Per Jessen, Zürich (5.8°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: strcmp() versus ==
On Mon, 16 Mar 2009 17:06:35 -0500, nos...@mckenzies.net (Shawn McKenzie) wrote: Shawn McKenzie wrote: Paul M Foster wrote: I had never completely read over the rules with regard to comparisons in PHP, and was recently alarmed to find that $str1 == $str2 might not compare the way I thought they would. Is it common practice among PHP coders to use strcmp() instead of == in making string comparisons? Or am I missing/misreading something? Paul I would use $str1 === $str2 if you want to make sure they are both strings and both the same value. Since PHP is loosely typed, 0 == 0 is true however 0 === 0 is false. If you want to force a string comparison you can also use: (string)$str1 == (string)$str2 Recently there was some discussion about inexplicable results from sorting alphanumeric strings. Inspired by your suggestion I filled in an array with random 4 character alphanumeric strings, and then wrote a simple bubblesort. I made two copies of the array, and sorted one using a simple comparison, and the other using the above comparison. The initial values of the array were : $aa = array ('ASDF','01A3','0A13',1,'00A3','','001A','','7205','00Z0'); (There are no letter 'O's in this), And the results I got were: Tb2_38: Original Raw comp String Comp ASDF 01A300A3 001A 0A1301A3 00A3 1 0A13 00Z0 00A3ASDF 01A3 0A13 001A1 1 001A 7205 720500Z0 ASDF 00Z07205 Apart from the out of place '1', apparently treated as '1000', which I threw in out of curiosity, the string comparison gave the expected results, but I cannot see the logic of the raw comparison. Can anybody explain these results? Clancy If anyone is suspicious the actual code I used was: $aa = array ('ASDF','01A3','0A13',1,'00A3','','001A','','7205','00Z0'); $k = count ($aa); $bb = $aa; $cc = $aa; while ($k 1) { $i = 0; $j = 1; while ($j $k) { if ($cc[$i] $cc[$j]) { $t = $cc[$i]; $cc[$i] = $cc[$j]; $cc[$j] = $t; } ++$i; ++$j; } --$k; } $k = count ($aa); while ($k 1) { $i = 0; $j = 1; while ($j $k) { if ((string)$bb[$i] (string)$bb[$j]) { $t = $bb[$i]; $bb[$i] = $bb[$j]; $bb[$j] = $t; } ++$i; ++$j; } --$k; } echo 'pTb2_38: Originalnbsp;nbsp;nbsp;Raw comp nbsp;nbsp;String Comp/p'; $i = 0; $k = count ($aa); while ($i $k) { echo 'pnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; '.$aa[$i]. 'nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;'.$cc[$i]. 'nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;'.$bb[$i].'/p'; ++$i; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Fork and zombies
Waynn Lue wrote: Ah, I was changing it to waiting for each child to finish in order to see if I could narrow down my db problem, because I figure this should be more or less equivalent to running it synchronously. Even like this, though, it still causes the db problem. I think the database problem is caused by your child inheriting the connection, and then closing it - whilst the parent is still using it. Your parent needs to open a new connection. /Per -- Per Jessen, Zürich (8.8°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Fork and zombies
Waynn Lue wrote: (Apologies for topposting, I'm on my blackberry). Hm, so you think exiting from the child thread causes the db resource to get reclaimed? Yeah, something like that. The connection is definitely closed when the child exits. /Per -- Per Jessen, Zürich (8.9°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Fork and zombies
I think your waitpid() is in the wrong place, and at least you need use WNOHANG - unless you specifically want to wait for each child to finish before starting another one. But it still has the same problem, and I'm also trying to avoid pcntl_wait or pcntl_waitpid at all because I still want to do it asynchronously. pcntl_wait(WNOHANG) will make everything work asynchronously. Ah, I was changing it to waiting for each child to finish in order to see if I could narrow down my db problem, because I figure this should be more or less equivalent to running it synchronously. Even like this, though, it still causes the db problem.
[PHP] Re: Studying IF statements
Shawn Thanks for the help, and your right, I peeked ahead and the lesson goes in that direction. Thanks again Gary Shawn McKenzie nos...@mckenzies.net wrote in message news:cf.57.22219.f310f...@pb1.pair.com... Shawn McKenzie wrote: Gary wrote: Shawn Thanks for your reply. Some of what you are saying is a little ahead of my lessons, but let me address as best I can. The script worked fine in the previous lesson where I was to send emails from my DB, this lesson is to kill the email from being sent if empty. On your very first line you haven't surround the email in quotes (only one quote). That worked fine with the single quotes and is listed in the book that way. Then later in the line $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); you're missing a quote before hostet. The single quote was deleted when I was sanitizing the code to post here, but it is in the code...sorry. So the jist of what you are saying is to add die after the if statements...but they are not in the book * I tried your code and it was not working either, am getting a parse error Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in on line 109 Line 109 die 'You forgot to enter a subject and or text in the body! br/Click the back buttonbr /'; Shawn McKenzie nos...@mckenzies.net wrote in message news:b8.22.22219.724fe...@pb1.pair.com... Gary wrote: Reading a book on php/mysql (Head First) and the following code is not working, athough I am pretty sure I have it as they say to. Trying to kill a sendmail script if I forget to enter a subject or text in body of email. I am getting the echo, but it is still sending the emails out. What am I missing here? Thanks. Gary ?php $from = em...@email.com'; $subject =$_POST['subject']; $text =$_POST['body_of_mail']; if(empty($subject)) { if(empty($body_of_mail)){ echo 'You forgot to enter a subject and or text in the body! br /'; $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); $query = SELECT * FROM table; $result = mysqli_query($dbc, $query) or die('Error querying database.'); while ($row = mysqli_fetch_array($result)) { $to = $row['email']; $first_name = $row['first_name']; $last_name = $row['last_name']; $msg = Dear $first_name $last_name,\n$text; mail($to, $subject, $msg, 'From:' . $from); echo 'Email sent to: ' . $to . 'br /'; } $msg =Dear $first_name.' '.$last_name\n $text; mail($to,$subject,$msg,$from); echo Email sent to: $to br / ; mysqli_close($dbc); } } ? Well, first, it shouldn't do anything because you have parse errors that should stop the script. On your very first line you haven't surround the email in quotes (only one quote). Then later in the line $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); you're missing a quote before hostet. Second, you look for empty vars and if they are empty then you echo that they forgot to enter them but go on to send the emails anyway. Then you loop through a database result and send to everyone and then you send another one to the last person you just sent to. Try this: ?php $from = 'em...@email.com'; $subject =$_POST['subject']; $text =$_POST['body_of_mail']; if(empty($subject) || empty($body_of_mail)) { die 'You forgot to enter a subject and or text in the body! br /Click the back buttonbr /'; } else { $dbc = mysqli_connect('hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); $query = SELECT * FROM table; $result = mysqli_query($dbc, $query) or die('Error querying database.'); while ($row = mysqli_fetch_array($result)) { $to = $row['email']; $first_name = $row['first_name']; $last_name = $row['last_name']; $msg = Dear $first_name $last_name,\n$text; mail($to, $subject, $msg, 'From:' . $from); echo 'Email sent to: ' . $to . 'br /'; } mysqli_close($dbc); } ? -- Thanks! -Shawn http://www.spidean.com So goes the typing code in to email :-) Try replacing the die line with: die('You forgot to enter a subject and or text in the body!br /Click the back button.br /'); This is just an example using the code that you posted as a learning exercise. Your original IF said: if $subject is empty, then evaluate the next if $body_of_mail is empty, if so, then echo 'You forgot to enter a subject and or text in the body! br /' THEN execute the rest of the code which returns records from the db and then loops through them and send an email to the addresses from the db query. I just added a die() which kills the script execution IF the fields are empty and an ELSE, which is evaluated if the fields are NOT empty, that does the db query and email. In a real world example, instead of die() you might reload the form and display a
Re: [PHP] Anyone know of a project like Redmine written in PHP?
Yes, recently the developer of JotBug anounced his project. I guess the project still needs help. All I have is the public CVS acces so far.. Check out http://www.jotbug.org/projects http://code.google.com/p/jotbug/ byebye 2009/3/17 mike mike...@gmail.com: http://www.redmine.org/ Looks pretty useful; I want one in PHP though. Anyone? -- 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
[PHP] Re: Fork and zombies
(Apologies for topposting, I'm on my blackberry). Hm, so you think exiting from the child thread causes the db resource to get reclaimed? On 3/17/09, Per Jessen p...@computer.org wrote: Waynn Lue wrote: Ah, I was changing it to waiting for each child to finish in order to see if I could narrow down my db problem, because I figure this should be more or less equivalent to running it synchronously. Even like this, though, it still causes the db problem. I think the database problem is caused by your child inheriting the connection, and then closing it - whilst the parent is still using it. Your parent needs to open a new connection. /Per -- Per Jessen, Zürich (8.8°C) -- 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
[PHP] Multithreading in PHP
Hi Guys, I am creating a page which submits the form through Ajax request the submitted page is sending the mails to n number of users. Now until the mail sends or the page process completed the end user has to wait. Is it possible that server sends the response to the client then start processing so that the client doesn't have to wait for the server response. Please suggest. Regards, Manoj
Re: [PHP] Multithreading in PHP
Hi Alpar, Thanks for reply. Actually the form is submitted through ajax request and the validation is checking on the server side. So if any error occurs on submission of form, then we are displaying the errors to the user. And is there is no error, then the submitted page started processing. So here client has to wait until the page process completed or not. What i want here if possible, after validating the user input server sends the thanks response to the client so that cleint doesn't has to wait, then the server starts the processing. Please suggest if it is possible. Regards, Manoj On Tue, Mar 17, 2009 at 7:01 PM, Alpár Török torokal...@gmail.com wrote: 2009/3/17 Manoj Singh manojsingh2...@gmail.com: Hi Guys, I am creating a page which submits the form through Ajax request the submitted page is sending the mails to n number of users. Now until the mail sends or the page process completed the end user has to wait. Is it possible that server sends the response to the client then start processing so that the client doesn't have to wait for the server response. Please suggest. Regards, Manoj Since you are using Ajax requests, which by their nature are asynchronous , your user won't have to wait. You can write some JS code to let him know that the request was sent, and just let the ajax call run in the background. On the server side make sure to ignore user abort, just in case the user navigates away. -- Alpar Torok
[PHP] /home/{user}/directory
In my scripts, I usually define a boolean constant DEBUG. True looks for local copies of includes and echoes queries as they're used. My question is: Is there any way for me to reflect the actual home folder of the person running the script? So it will be /home/george/foo when I run it but, for another user, it would be /home/their-username/foo?
Re: [PHP] Multithreading in PHP
2009/3/17 Manoj Singh manojsingh2...@gmail.com: Hi Guys, I am creating a page which submits the form through Ajax request the submitted page is sending the mails to n number of users. Now until the mail sends or the page process completed the end user has to wait. Is it possible that server sends the response to the client then start processing so that the client doesn't have to wait for the server response. Please suggest. Regards, Manoj Since you are using Ajax requests, which by their nature are asynchronous , your user won't have to wait. You can write some JS code to let him know that the request was sent, and just let the ajax call run in the background. On the server side make sure to ignore user abort, just in case the user navigates away. -- Alpar Torok -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multithreading in PHP
My suggestion is that you can start a second ajax as soon as the response about validating data is returned to process everithing you need and so your user wont wait until the process is finished. João Cândido Manoj Singh manojsingh2...@gmail.com escreveu na mensagem news:3859a530903170639m6c2af2b2s941446a31103c...@mail.gmail.com... Hi Alpar, Thanks for reply. Actually the form is submitted through ajax request and the validation is checking on the server side. So if any error occurs on submission of form, then we are displaying the errors to the user. And is there is no error, then the submitted page started processing. So here client has to wait until the page process completed or not. What i want here if possible, after validating the user input server sends the thanks response to the client so that cleint doesn't has to wait, then the server starts the processing. Please suggest if it is possible. Regards, Manoj On Tue, Mar 17, 2009 at 7:01 PM, Alpár Török torokal...@gmail.com wrote: 2009/3/17 Manoj Singh manojsingh2...@gmail.com: Hi Guys, I am creating a page which submits the form through Ajax request the submitted page is sending the mails to n number of users. Now until the mail sends or the page process completed the end user has to wait. Is it possible that server sends the response to the client then start processing so that the client doesn't have to wait for the server response. Please suggest. Regards, Manoj Since you are using Ajax requests, which by their nature are asynchronous , your user won't have to wait. You can write some JS code to let him know that the request was sent, and just let the ajax call run in the background. On the server side make sure to ignore user abort, just in case the user navigates away. -- Alpar Torok -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] /home/{user}/directory
On Tue, Mar 17, 2009 at 10:42 AM, George Larson george.g.lar...@gmail.comwrote: In my scripts, I usually define a boolean constant DEBUG. True looks for local copies of includes and echoes queries as they're used. My question is: Is there any way for me to reflect the actual home folder of the person running the script? So it will be /home/george/foo when I run it but, for another user, it would be /home/their-username/foo? Just checking, you're running PHP on CLI then, right? If it's running on normal apache setup the user would always be the user which apache is running. Thiago Henrique Pojda http://nerdnaweb.blogspot DOT com
Re: [PHP] /home/{user}/directory
Thanks! On Tue, Mar 17, 2009 at 9:46 AM, Stuart stut...@gmail.com wrote: 2009/3/17 George Larson george.g.lar...@gmail.com In my scripts, I usually define a boolean constant DEBUG. True looks for local copies of includes and echoes queries as they're used. My question is: Is there any way for me to reflect the actual home folder of the person running the script? So it will be /home/george/foo when I run it but, for another user, it would be /home/their-username/foo? $dir = realpath('~/foo'); -Stuart -- http://stut.net/
Re: [PHP] /home/{user}/directory
That is correct. PHP on CLI. Thanks! On Tue, Mar 17, 2009 at 9:51 AM, Thiago H. Pojda thiago.po...@gmail.comwrote: On Tue, Mar 17, 2009 at 10:42 AM, George Larson george.g.lar...@gmail.com wrote: In my scripts, I usually define a boolean constant DEBUG. True looks for local copies of includes and echoes queries as they're used. My question is: Is there any way for me to reflect the actual home folder of the person running the script? So it will be /home/george/foo when I run it but, for another user, it would be /home/their-username/foo? Just checking, you're running PHP on CLI then, right? If it's running on normal apache setup the user would always be the user which apache is running. Thiago Henrique Pojda http://nerdnaweb.blogspot DOT com
Re: [PHP] Multithreading in PHP
Manoj Singh wrote: Hi Guys, I am creating a page which submits the form through Ajax request the submitted page is sending the mails to n number of users. Now until the mail sends or the page process completed the end user has to wait. Is it possible that server sends the response to the client then start processing so that the client doesn't have to wait for the server response. I can think of two ways to solve this apart from creating an Ajax request: 1. Queue the emails. Run a cron job to process the queue later. 2. Send the email after you flush the output. -- With warm regards, Sudheer. S Business: http://binaryvibes.co.in, Tech stuff: http://techchorus.net, Personal: http://sudheer.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multithreading in PHP
Hi Sudheer, Can you please put more focus or sample code for the second option which you have suggested Send the email after you flush the output.. Regards, Manoj On Tue, Mar 17, 2009 at 7:28 PM, Sudheer Satyanarayana sudhee...@binaryvibes.co.in wrote: Manoj Singh wrote: Hi Guys, I am creating a page which submits the form through Ajax request the submitted page is sending the mails to n number of users. Now until the mail sends or the page process completed the end user has to wait. Is it possible that server sends the response to the client then start processing so that the client doesn't have to wait for the server response. I can think of two ways to solve this apart from creating an Ajax request: 1. Queue the emails. Run a cron job to process the queue later. 2. Send the email after you flush the output. -- With warm regards, Sudheer. S Business: http://binaryvibes.co.in, Tech stuff: http://techchorus.net, Personal: http://sudheer.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multithreading in PHP
Manoj Singh wrote: Hi Sudheer, Can you please put more focus or sample code for the second option which you have suggested Send the email after you flush the output.. ?php //Code to send some output to user ... ... ... echo Email will be sent to you shortly; //Time to send email //Send all other output before this line ob_flush(); flush(); //Code to send email //echo Email sent; -- With warm regards, Sudheer. S Business: http://binaryvibes.co.in, Tech stuff: http://techchorus.net, Personal: http://sudheer.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] /home/{user}/directory
2009/3/17 George Larson george.g.lar...@gmail.com In my scripts, I usually define a boolean constant DEBUG. True looks for local copies of includes and echoes queries as they're used. My question is: Is there any way for me to reflect the actual home folder of the person running the script? So it will be /home/george/foo when I run it but, for another user, it would be /home/their-username/foo? $dir = realpath('~/foo'); -Stuart -- http://stut.net/
[PHP] Re: strcmp() versus ==
Clancy wrote: On Mon, 16 Mar 2009 17:06:35 -0500, nos...@mckenzies.net (Shawn McKenzie) wrote: Shawn McKenzie wrote: Paul M Foster wrote: I had never completely read over the rules with regard to comparisons in PHP, and was recently alarmed to find that $str1 == $str2 might not compare the way I thought they would. Is it common practice among PHP coders to use strcmp() instead of == in making string comparisons? Or am I missing/misreading something? Paul I would use $str1 === $str2 if you want to make sure they are both strings and both the same value. Since PHP is loosely typed, 0 == 0 is true however 0 === 0 is false. If you want to force a string comparison you can also use: (string)$str1 == (string)$str2 Recently there was some discussion about inexplicable results from sorting alphanumeric strings. Inspired by your suggestion I filled in an array with random 4 character alphanumeric strings, and then wrote a simple bubblesort. I made two copies of the array, and sorted one using a simple comparison, and the other using the above comparison. The initial values of the array were : $aa = array ('ASDF','01A3','0A13',1,'00A3','','001A','','7205','00Z0'); (There are no letter 'O's in this), And the results I got were: Tb2_38: Original Raw comp String Comp ASDF 01A300A3 001A 0A1301A3 00A3 1 0A13 00Z0 00A3ASDF 01A3 0A13 001A1 1 001A 7205 720500Z0 ASDF 00Z07205 Apart from the out of place '1', apparently treated as '1000', which I threw in out of curiosity, the string comparison gave the expected results, but I cannot see the logic of the raw comparison. Can anybody explain these results? Clancy If anyone is suspicious the actual code I used was: $aa = array ('ASDF','01A3','0A13',1,'00A3','','001A','','7205','00Z0'); $k = count ($aa); $bb = $aa; $cc = $aa; while ($k 1) { $i = 0; $j = 1; while ($j $k) { if ($cc[$i] $cc[$j]) { $t = $cc[$i]; $cc[$i] = $cc[$j]; $cc[$j] = $t; } ++$i; ++$j; } --$k; } $k = count ($aa); while ($k 1) { $i = 0; $j = 1; while ($j $k) { if ((string)$bb[$i] (string)$bb[$j]) { $t = $bb[$i]; $bb[$i] = $bb[$j]; $bb[$j] = $t; } ++$i; ++$j; } --$k; } echo 'pTb2_38: Originalnbsp;nbsp;nbsp;Raw comp nbsp;nbsp;String Comp/p'; $i = 0; $k = count ($aa); while ($i $k) { echo 'pnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; '.$aa[$i]. 'nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;'.$cc[$i]. 'nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;'.$bb[$i].'/p'; ++$i; } Just a quick look, your original post was about comparing strings and as far as I know, unless you force a string comparison the and will do a numerical comparison, and even if I'm wrong, anything compared to your 1 will be a numerical comparison. If your just trying to sort, check out sort() and natsort(). -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Check this out - Videos on how to protect your website against hackers
Hi! Thank you for checking out this thread. I'm working on some killer videos right now that will explain in detail how you can protect your website against hackers. The first part of the video series is live right now and it covers Cross-Site Request Forgery (CSRF). Go ahead and check them out right now: www.aachen-method.com This knowledge is essential in making your websites secure and once you have a deep understanding of PHP security you can confidently charge higher rates when you are programming for other people. I have worked hard on making my videos easy to understand and if you watch them in sequence you will have no problem keeping up, even if you are just starting out with PHP programming. You can just copy and paste everything right into your code, it's that simple! The only thing that you might have to change is variable names so that it works with your code and that shouldn't be a problem. And I have inserted my e-mail address at the end of every video if you happen to have a question, so please don't hesitate to contact me and I'll try to get back to you as soon as I can. There is no sales pitch anywhere on that website, not even ads! This is because I've been programming PHP since 2001 and since the PHP community has given me so much over the years I now want to give back by providing some killer content. I realize that some people might regard this message as spam, especially because I'm new to this forum. However please understand that I'm just trying to show these videos to as many people as possible so that we as a community can start to eliminate these vulnerabilities from people's PHP code. Arne P.S.: Here's the link again: www.aachen-method.com -- View this message in context: http://www.nabble.com/Check-this-out---Videos-on-how-to-protect-your-website-against-hackers-tp22565598p22565598.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Anyone know of a project like Redmine written in PHP?
mike wrote: http://www.redmine.org/ Looks pretty useful; I want one in PHP though. Anyone? Mantis Bug Tracker has some of the features you are looking for: http://www.mantisbt.org/ -- Micah -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: mail() is duplicating
On Fri, 2009-03-13 at 22:54 -0300, Manuel Lemos wrote: Hello, on 03/13/2009 05:37 PM Rick Pasotto said the following: I have several forms on my site that use the same sequence of events: The first script displays and validates the form data, the second reformats and asks for confirmation or editing, and the third script sends the data in an email to the relevent people. Two of these forms work exactly as they're supposed to but the third sends duplicate emails to everyone. I have looked and looked and I've run diff and I can see no reason why this should be happening. Could someone suggest what I might have wrong? Usually this happens when you have a To: header in the headers parameters. -- Regards, Manuel Lemos Find and post PHP jobs http://www.phpclasses.org/jobs/ PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ Another possibility is that the mail sending is triggered from a page that is called from a get request rather than post. Some browsers actually make more than one call when the page is get, thereby triggering the duplicate mail creation. I had a similar thing with a database update once before, it's a bugger to be rid of without switching to post. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Multithreading in PHP
Hello, on 03/17/2009 10:14 AM Manoj Singh said the following: I am creating a page which submits the form through Ajax request the submitted page is sending the mails to n number of users. Now until the mail sends or the page process completed the end user has to wait. Is it possible that server sends the response to the client then start processing so that the client doesn't have to wait for the server response. You will need to use AJAX/COMET requests. Regular XMLHttpRequest AJAX requests will not do because when you send the AJAX response your script exits. With AJAX/COMET requests you can send several responses to the same request without exiting the script, so you can show progress report. Take a look at these articles: http://www.phpclasses.org/blog/post/58-Responsive-AJAX-applications-with-COMET.html http://www.phpclasses.org/blog/post/51-PHPClasses-20-Beta-AJAX-XMLHttpRequest-x-IFrame.html This forms class comes with an AJAX/COMET plug-in that allows you to show progress of a task running on the server without page reloading in a single request. http://www.phpclasses.org/formsgeneration Here is is a live example script that show progress of a task running on the server after the form is submitted. http://www.meta-language.net/forms-examples.html?example=test_ajax_form -- Regards, Manuel Lemos Find and post PHP jobs http://www.phpclasses.org/jobs/ PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Fork and zombies
Per Jessen schreef: Waynn Lue wrote: (Apologies for topposting, I'm on my blackberry). Hm, so you think exiting from the child thread causes the db resource to get reclaimed? Yeah, something like that. The connection is definitely closed when the child exits. I can confirm this. you definitely need to open a connection for each child process. if you require a db connection in the parent process, you should close it before forking (and then reopen it afterwards if you still need it). at least that's what I found I had to do when I ran into this. incidently my forking loop looks like this, very interested to know if Per can spot any obvious stupidity: $childProcs = array(); do { if (count($childProcs) = $maxChildProcs) { $site = array_shift($sites); $pid = pcntl_fork(); } else { // stay as parent, no fork, try to reduce number of child processes $site = null; $pid = null; } switch (true) { case ($pid === -1): cronLog(error: (in {$thisScript}), cannot initialize worker process in order to run {$script} for {$site['name']}); break; case ($pid === 0): // we are child $exit = 0; $output = array(); // do we want to exec? or maybe include? if ($doExec) { exec($script.' '.$site['id'], $output, $exit); } else { $output = inc($script); $output = explode(\n, $output); } if ($exit != 0) cronLog(error: (in {$thisScript}), {$script} reported an error ($exit) whilst processing for {$site['name']},); foreach ($output as $line) cronLog($line); exit($exit); break; default: // we are parent $childProcs[] = $pid; do { $status = null; while (pcntl_wait($status, WNOHANG | WUNTRACED) 1) usleep(5); foreach ($childProcs as $k = $v) if (!posix_kill($v, 0)) // send signal 'zero' to check whether process is still 'up' unset($childProcs[ $k ]); $childProcs = array_values($childProcs); if (count($sites)) break; // more sites to run the given script for if (!count($childProcs)) break; // no more sites to run the given script for and all children are complete/dead } while (true); break; } if (!count($sites)) break; // nothing more to do usleep(5); } while (true); /Per -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Fork and zombies
If Fork and Zombies was a diner... I would totally eat there. On Tue, Mar 17, 2009 at 5:00 PM, Jochem Maas joc...@iamjochem.com wrote: Per Jessen schreef: Waynn Lue wrote: (Apologies for topposting, I'm on my blackberry). Hm, so you think exiting from the child thread causes the db resource to get reclaimed? Yeah, something like that. The connection is definitely closed when the child exits. I can confirm this. you definitely need to open a connection for each child process. if you require a db connection in the parent process, you should close it before forking (and then reopen it afterwards if you still need it). at least that's what I found I had to do when I ran into this. incidently my forking loop looks like this, very interested to know if Per can spot any obvious stupidity: $childProcs = array(); do { if (count($childProcs) = $maxChildProcs) { $site = array_shift($sites); $pid = pcntl_fork(); } else { // stay as parent, no fork, try to reduce number of child processes $site = null; $pid = null; } switch (true) { case ($pid === -1): cronLog(error: (in {$thisScript}), cannot initialize worker process in order to run {$script} for {$site['name']}); break; case ($pid === 0): // we are child $exit = 0; $output = array(); // do we want to exec? or maybe include? if ($doExec) { exec($script.' '.$site['id'], $output, $exit); } else { $output = inc($script); $output = explode(\n, $output); } if ($exit != 0) cronLog(error: (in {$thisScript}), {$script} reported an error ($exit) whilst processing for {$site['name']},); foreach ($output as $line) cronLog($line); exit($exit); break; default: // we are parent $childProcs[] = $pid; do { $status = null; while (pcntl_wait($status, WNOHANG | WUNTRACED) 1) usleep(5); foreach ($childProcs as $k = $v) if (!posix_kill($v, 0)) // send signal 'zero' to check whether process is still 'up' unset($childProcs[ $k ]); $childProcs = array_values($childProcs); if (count($sites)) break; // more sites to run the given script for if (!count($childProcs)) break; // no more sites to run the given script for and all children are complete/dead } while (true); break; } if (!count($sites)) break; // nothing more to do usleep(5); } while (true); /Per -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Fork and zombies
On Tue, 2009-03-17 at 17:06 -0400, George Larson wrote: If Fork and Zombies was a diner... I would totally eat there. For fork sake... ;) Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Fork and zombies
Jochem Maas wrote: Per Jessen schreef: Waynn Lue wrote: (Apologies for topposting, I'm on my blackberry). Hm, so you think exiting from the child thread causes the db resource to get reclaimed? Yeah, something like that. The connection is definitely closed when the child exits. I can confirm this. you definitely need to open a connection for each child process. if you require a db connection in the parent process, you should close it before forking (and then reopen it afterwards if you still need it). Yep, exactly my thinking. at least that's what I found I had to do when I ran into this. incidently my forking loop looks like this, very interested to know if Per can spot any obvious stupidity: I doubt it. I can't quite follow your code after the pcntl_wait where you've got a pcntl_kill(), but it looks like an insurance policy? just in case ? /Per -- Per Jessen, Zürich (7.0°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: mail() is duplicating
Hello, on 03/17/2009 05:34 PM Ashley Sheridan said the following: I have several forms on my site that use the same sequence of events: The first script displays and validates the form data, the second reformats and asks for confirmation or editing, and the third script sends the data in an email to the relevent people. Two of these forms work exactly as they're supposed to but the third sends duplicate emails to everyone. I have looked and looked and I've run diff and I can see no reason why this should be happening. Could someone suggest what I might have wrong? Usually this happens when you have a To: header in the headers parameters. Another possibility is that the mail sending is triggered from a page that is called from a get request rather than post. Some browsers actually make more than one call when the page is get, thereby triggering the duplicate mail creation. I had a similar thing with a database update once before, it's a bugger to be rid of without switching to post. I suspect that may happen with nervous users that double click form submit buttons. Usually I use this forms class that has a built-in feature to show a form resubmit confirmation message when the use uses the submit function more than once: http://www.phpclasses.org/formsgeneration That feature can be seen in this page: http://www.meta-language.net/forms-examples.html?example=test_form -- Regards, Manuel Lemos Find and post PHP jobs http://www.phpclasses.org/jobs/ PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Form to pdf
Is it possible to create an online form, that when filled out the fields will can be placed in a pdf form? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Fork and zombies
Per Jessen schreef: Jochem Maas wrote: Per Jessen schreef: Waynn Lue wrote: (Apologies for topposting, I'm on my blackberry). Hm, so you think exiting from the child thread causes the db resource to get reclaimed? Yeah, something like that. The connection is definitely closed when the child exits. I can confirm this. you definitely need to open a connection for each child process. if you require a db connection in the parent process, you should close it before forking (and then reopen it afterwards if you still need it). Yep, exactly my thinking. at least that's what I found I had to do when I ran into this. incidently my forking loop looks like this, very interested to know if Per can spot any obvious stupidity: I doubt it. I can't quite follow your code after the pcntl_wait where you've got a pcntl_kill(), but it looks like an insurance policy? just in case ? correct, from my reading the pcntl_kill() with a signal argument of zero should return true if it is *able* to send the signal (but it doesn't actually send anything), given that it's only checking it's own children the parent process must able to send them signals assuming they're not somehow dead ... so yeah, insurance policy :-) /Per -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] assign associative array values to variables?
I have been tearing out my hair to figure out a way to place array values into $variables with not much luck. I can echo the array to the screen but I can not manipulate the results. I have searched wide and far all day on the web and I find nothing that points the way how to extract values from an associative array and assign them to a variable. I expected to find some elegant way to do it. Here's the code that outputs the values: if ( isset( $book_categories[$bookID] ) ) { foreach ( $book_categories[$bookID] AS $categoryID ) { if ( isset( $category[$categoryID] ) ) { echo($category[$categoryID]['category']); } } } this will echo something like CivilizationGods And GoddessesHistorical PeriodsSociology Anthropology (I have not added breaks beween the categories as there is more manipulation needed on them) This works for as many categories as needed. Manipulating each value should not be a problem once it is in a string variable using switch and preg_replace() as each category needs to be stripped of spaces, commas and s. -- unheralded genius: A clean desk is the sign of a dull mind. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_replace() question
1. What is the overhead on preg_replace? 2. Is there a better way to strip spaces and non alpha numerical characters from text strings? I suspect not... maybe the Shadow does ??? :-D -- unheralded genius: A clean desk is the sign of a dull mind. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] assign associative array values to variables?
PJ wrote: I have been tearing out my hair to figure out a way to place array values into $variables with not much luck. I can echo the array to the screen but I can not manipulate the results. I have searched wide and far all day on the web and I find nothing that points the way how to extract values from an associative array and assign them to a variable. I expected to find some elegant way to do it. Here's the code that outputs the values: if ( isset( $book_categories[$bookID] ) ) { foreach ( $book_categories[$bookID] AS $categoryID ) { if ( isset( $category[$categoryID] ) ) { echo($category[$categoryID]['category']); } } } Same as other variable assignment. if ( isset( $category[$categoryID] ) ) { $myvar = $category[$categoryID]; } echo $myvar . br/; Doing it with a multi-dimensional array is no different to a result set from a database or any other scenario. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_replace() question
PJ wrote: 1. What is the overhead on preg_replace? Compared to what? If you write a 3 line regex, it's going to take some processing. 2. Is there a better way to strip spaces and non alpha numerical characters from text strings? I suspect not... maybe the Shadow does ??? For this, preg_replace is probably the right option. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Fork and zombies
Yeah, something like that. The connection is definitely closed when the child exits. I can confirm this. you definitely need to open a connection for each child process. if you require a db connection in the parent process, you should close it before forking (and then reopen it afterwards if you still need it). I thought that too, but this code seems to work, which seems to imply that the child doesn't kill the existing db connection. $conn = mysql_connect($sharedAppsDbHost, $sharedAppsDbUser, $sharedAppsDbPass, true); foreach ($things as $thing) { temp($thing); } function temp($thing) { global $conn; extract(getInfo($thing)); // this function call uses a shared db connection mysqlSelectDb($dbName, $conn); // dbName is a variable gotten from the above call $result = mysql_query(SELECT COUNT(*) FROM Users, $conn); $row = mysql_fetch_array($result, MYSQL_BOTH); echo $row[0]\n; $pid = pcntl_fork(); if ($pid == -1) { die(could not fork); } else if ($pid) { // parent, return the child pid echo child pid $pid waiting\n; pcntl_waitpid($pid, $status, WNOHANG); if (pcntl_wifexited($status)) { echo finished [$status] waiting\n; return; } } else { echo child sleeping\n; sleep(3); echo child done\n; exit; } } == My main problem here is that I have a set of helper functions (getInfo is one of them) that uses a global db connection that exists in that helper script. Otherwise, I have to rewrite the function to create a new connection every time, which I'd like not to. Waynn
Re: [PHP] Re: Fork and zombies
Yeah, something like that. The connection is definitely closed when the child exits. I can confirm this. you definitely need to open a connection for each child process. if you require a db connection in the parent process, you should close it before forking (and then reopen it afterwards if you still need it). I thought that too, but this code seems to work, which seems to imply that the child doesn't kill the existing db connection. $conn = mysql_connect($sharedAppsDbHost, $sharedAppsDbUser, $sharedAppsDbPass, true); foreach ($things as $thing) { temp($thing); } function temp($thing) { global $conn; extract(getInfo($thing)); // this function call uses a shared db connection mysqlSelectDb($dbName, $conn); // dbName is a variable gotten from the above call $result = mysql_query(SELECT COUNT(*) FROM Users, $conn); $row = mysql_fetch_array($result, MYSQL_BOTH); echo $row[0]\n; $pid = pcntl_fork(); if ($pid == -1) { die(could not fork); } else if ($pid) { // parent, return the child pid echo child pid $pid waiting\n; pcntl_waitpid($pid, $status, WNOHANG); if (pcntl_wifexited($status)) { echo finished [$status] waiting\n; return; } } else { echo child sleeping\n; sleep(3); echo child done\n; exit; } } == My main problem here is that I have a set of helper functions (getInfo is one of them) that uses a global db connection that exists in that helper script. Otherwise, I have to rewrite the function to create a new connection every time, which I'd like not to. Waynn Whoops, I spoke too soon, I think the sleep(3) causes the child not to exit before the parent. If instead I don't pass WNOHANG to the waitpid command, it does error out. So it looks like your theory is correct, and I still have that problem. I guess the only solution is to rewrite the functions to use a new db connection every time? Or maybe I should just sleep the child thread for long periods of time and hope the parent thread finishes in time (which admittedly seems really hacky)?
Re: [PHP] assign associative array values to variables?
Chris wrote: PJ wrote: I have been tearing out my hair to figure out a way to place array values into $variables with not much luck. I can echo the array to the screen but I can not manipulate the results. I have searched wide and far all day on the web and I find nothing that points the way how to extract values from an associative array and assign them to a variable. I expected to find some elegant way to do it. Here's the code that outputs the values: if ( isset( $book_categories[$bookID] ) ) { foreach ( $book_categories[$bookID] AS $categoryID ) { if ( isset( $category[$categoryID] ) ) { echo($category[$categoryID]['category']); } } } Same as other variable assignment. if ( isset( $category[$categoryID] ) ) { $myvar = $category[$categoryID]; } echo $myvar . br/; Doing it with a multi-dimensional array is no different to a result set from a database or any other scenario. I probably did not express myself clearly; I thought I did: place array * *values ** into * *$variables ** the output of $myvar above is Array. That, I knew. And that does not extract. I can see what is in the array in several ways; the problem is to get the output into $var1, $var2, $var3 ... etc. How do I convert: $category[$categoryID]['category'] into up to 4 different variables that I can manipulate? My code above outputs text like this: CivilizationGods And GoddessesHistorical PeriodsSociology Anthropology -- unheralded genius: A clean desk is the sign of a dull mind. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] assign associative array values to variables?
dg wrote: If I'm understanding your question correctly, this may help: ?php $array = array(value_one = red, value_two = blue); extract($array); print $value_one, $value_two; Thanks for the suggestion. I've seen that example and have tried it as well as about a dozen others. The problem is that the $array returns another array (multidimensional and associative ?? ) print_r($myarray) returns for example: Array ( [id] = 5 [category] = Some category) Array ( [id] = 33 [category] = Another category) So, you see, I can't do anything with that. I had hoped to be able to use something like count() or $row() or foreach or while but no go. foreach may have a possibility but it it rather convoluted and I'm trying to avoid it; hoping for something simpler, more logical and more elegant. ? On Mar 17, 2009, at 4:27 PM, PJ wrote: I have been tearing out my hair to figure out a way to place array values into $variables with not much luck. I can echo the array to the screen but I can not manipulate the results. I have searched wide and far all day on the web and I find nothing that points the way how to extract values from an associative array and assign them to a variable. I expected to find some elegant way to do it. Here's the code that outputs the values: if ( isset( $book_categories[$bookID] ) ) { foreach ( $book_categories[$bookID] AS $categoryID ) { if ( isset( $category[$categoryID] ) ) { echo($category[$categoryID]['category']); } } } this will echo something like CivilizationGods And GoddessesHistorical PeriodsSociology Anthropology (I have not added breaks beween the categories as there is more manipulation needed on them) This works for as many categories as needed. Manipulating each value should not be a problem once it is in a string variable using switch and preg_replace() as each category needs to be stripped of spaces, commas and s. -- unheralded genius: A clean desk is the sign of a dull mind. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- unheralded genius: A clean desk is the sign of a dull mind. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] assign associative array values to variables?
PJ wrote: Chris wrote: PJ wrote: I have been tearing out my hair to figure out a way to place array values into $variables with not much luck. I can echo the array to the screen but I can not manipulate the results. I have searched wide and far all day on the web and I find nothing that points the way how to extract values from an associative array and assign them to a variable. I expected to find some elegant way to do it. Here's the code that outputs the values: if ( isset( $book_categories[$bookID] ) ) { foreach ( $book_categories[$bookID] AS $categoryID ) { if ( isset( $category[$categoryID] ) ) { echo($category[$categoryID]['category']); } } } Same as other variable assignment. if ( isset( $category[$categoryID] ) ) { $myvar = $category[$categoryID]; } echo $myvar . br/; Doing it with a multi-dimensional array is no different to a result set from a database or any other scenario. I probably did not express myself clearly; I thought I did: place array * *values ** into * *$variables ** Try this $my_categories = array(); foreach (..) { if (isset($category[$categoryID])) { $my_categories[] = $category[$categoryID]['category']; } } At the end, you can either: foreach ($my_categories as $category_name) { .. do something } or $category_list = implode(',', $my_categories); echo The categories are ${category_list}\n; -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Anyone know of a project like Redmine written in PHP?
Hmmm needs some help indeed... http://www.jotbug.org/help Jan G.B. wrote: Yes, recently the developer of JotBug anounced his project. I guess the project still needs help. All I have is the public CVS acces so far.. Check out http://www.jotbug.org/projects http://code.google.com/p/jotbug/ byebye 2009/3/17 mike mike...@gmail.com: http://www.redmine.org/ Looks pretty useful; I want one in PHP though. Anyone? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form to pdf
On Wed, Mar 18, 2009 at 3:48 AM, Gary gwp...@ptd.net wrote: Is it possible to create an online form, that when filled out the fields will can be placed in a pdf form? Yes possible. But you wrote the query in a bit confused way. Trying to rephrase yours: you want a form which will let user choose a working form to be placed in a PDF to be generated? www.twitter.com/nine_L -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Calendar/Date
Hi All, Does anyone have code and/or advice for how to get get the current week (with a passed current day, say) and what then end date is at Saturday. So take today: Tuesday March 17, 2009 I want to get: Sunday March 15, 2009 Monday March 16, 2009 Tuesday March 17, 2009 Wednesday March 18, 2009 Thursday March 19, 2009 Friday March 20, 2009 Saturday March 21, 2009 Thanks! -Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] php-general-sc.1237291233.npmhceaklghpccnefjed-born2victory=gmail....@lists.php.net
Re: [PHP] Calendar/Date
On Tue, Mar 17, 2009 at 08:52:11PM -0700, Jason Todd Slack-Moehrle wrote: Hi All, Does anyone have code and/or advice for how to get get the current week (with a passed current day, say) and what then end date is at Saturday. So take today: Tuesday March 17, 2009 I want to get: Sunday March 15, 2009 Monday March 16, 2009 Tuesday March 17, 2009 Wednesday March 18, 2009 Thursday March 19, 2009 Friday March 20, 2009 Saturday March 21, 2009 I just answered a question similar to this. You might check the archives. In this case, you'll need to use the getdate() function (see php.net/manual/en/ for details) to get the array of values for today (like the day of the month, month number, year, etc.). The getdate() function returns an array, one of whose members is 'wday', which is the day of the week, starting with 0 for Sunday. Use that number to determine how many days to go back from today. Then use mktime() to get the timestamps for each day in turn. You feed mktime() values from the getdate() call. Then you can use strftime() or something else to print out the dates in whatever format, given the timestamps you got. Be careful in feeding values to mktime(). If your week spans a month or year boundary, you'll need to compensate for it when giving mktime() month numbers, day numbers and year numbers. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP Quiz
Hello Friends, I have started a FREE site for quizzes for PHP. I need your kind help, if possible please visit the site and take some quizzes, and then let me know your feedback. Should I add any thing else in that site? link: http://www.testmyphp.com Thanks in advance. -- Satya Bangalore. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php