Re: [PHP] PHP String convention
2009/10/28 Warren Vail war...@vailtech.net: The curly braces look like something from the smarty template engine. Warren Vail Odd. I always thought the curly braces in the Smarty engine looked like something from PHP. :) Torben -Original Message- From: Kim Madsen [mailto:php@emax.dk] Sent: Wednesday, October 28, 2009 10:18 AM To: Nick Cooper Cc: Jim Lucas; php-general@lists.php.net Subject: Re: [PHP] PHP String convention Hi Nick Nick Cooper wrote on 2009-10-28 17:29: Thank you for the quick replies. I thought method 2 must be faster because it doesn't have to search for variables in the string. So what is the advantages then of method 1 over 3, do the curly braces mean anything? 1) $string = foo{$bar}; 2) $string = 'foo'.$bar; 3) $string = foo$bar; I must admit reading method 1 is easier, but writing method 2 is quicker, is that the only purpose the curly braces serve? Yes, you're right about that. 10 years ago I went to a seminar were Rasmus Lerforf was speaking and asked him exactly that question. The single qoutes are preferred and are way faster because it doesn´t have to parse the string, only the glued variables. Also we discussed that if you´re doing a bunch of HTML code it's considerably faster to do: tr td?= $data ?/td /tr Than print \n\ttr \n\t\ttd$data/td \n\t/tr; or print ' tr td'.$data.'/td /tr'; I remember benchmark testing it afterwards back then and there was clearly a difference. -- Kind regards Kim Emax - masterminds.dk -- 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 General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP String convention
2009/11/4 Nathan Rixham nrix...@gmail.com: Nick Cooper wrote: Hi, I was just wondering what the difference/advantage of these two methods of writing a string are: 1) $string = foo{$bar}; 2) $string = 'foo'.$bar; 1) breaks PHPUnit when used in classes (need to bug report that) 2) [concatenation] is faster (but you wouldn't notice) comes down to personal preference and what looks best in your (teams) IDE I guess; legibility (and possibly portability) is probably the primary concern. I would tend to agree here; the concat is faster but you may well only notice in very tight loops. The curly brace syntax can increase code readability, depending on the complexity of the expression. I use them both depending on the situation. Remember the rules of optimization: 1) Don't. 2) (Advanced users only): Optimize later. Write code so that it's readable, and then once it's working, identify the bottlenecks and optimize where needed. If you understand code analysis and big-O etc then you will start to automatically write mostly-optimized code anyway and in general, I doubt that you'll often identify the use of double quotes as a bottleneck--it almost always turns out that other operations and code structures are far more expensive and impact code speed much more. That said, you don't really lose anything by using concatenation from the start, except perhaps some legibility, so as Nathan said it often really just comes down to personal preference and perhaps the house coding conventions. Regards, Torben PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to bypass (pipe) curl_exec return value directly to a file?
2009/10/12 m.hasibuan magda.hasib...@yahoo.co.uk: Newbie question. I need to download a very large amount of xml data from a site using CURL. How to bypass (pipe) curl_exec return value directly to a file, without using memory allocation? set_time_limit(0); $ch = curl_init($siteURL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $mixed = curl_exec($ch); How to set/pipe $mixed as a (disk) file, so that data returned by curl_exec is directly saved to the disk-file, and not involving memory allocation? Thank you. Use the CURLOPT_FILE option to set the output to write to the file handle given by the option's value (which must be a writable file handle). For instance: $ch = curl_init($url); $fp = fopen('/tmp/curl.out', 'w'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec($ch); Error checking etc. is of course left up to you. :) Good luck, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to bypass (pipe) curl_exec return value directly to a file?
2009/10/13 Andrea Giammarchi an_...@hotmail.com: $ch = curl_init($url); $fp = fopen('/tmp/curl.out', 'w'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec($ch); Error checking etc. is of course left up to you. :) oops, I sent directly the file name. Let me reformulate the code then: set_time_limit(0); $fp = fopen('stream.bin', 'wb'); $ch = curl_init($siteURL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); If you're re-using a curl handle then it may be a good idea to set these explicitly. However, these are also the default values so it's not really necessary to set them for a new handle. You're right that it's a good idea to include the 'b' in the fopen() mode. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); I wouldn't recommend setting this to 0 unless you're very sure that the connection will succeed; otherwise, your script will hang indefinitely waiting for the connection to be made. Regards, Torben curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec($ch); fclose($fp); Apologize I did not test it before. Regards Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to bypass (pipe) curl_exec return value directly to a file?
2009/10/13 Andrea Giammarchi an_...@hotmail.com: curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); I wouldn't recommend setting this to 0 unless you're very sure that the connection will succeed; otherwise, your script will hang indefinitely waiting for the connection to be made. agreed, it's just he set timeout to zero so I guess he meant the curl connection as well otherwise it does not make sense to set the timeout to 0 if curl has 10 seconds timeout :-) Regards If he wants to download a very large file then it would make sense to set_time_limit(0) but leave the curl connect timeout enabled; he wouldn't want the PHP script timing out partway through a large download. :) The curl timeout isn't for the transfer; just for making the connection. Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable name as a variable?
On Mon, 5 Oct 2009 16:56:48 +0200 Dotan Cohen dotanco...@gmail.com wrote: I need to store a variable name as a variable. Note quite a C-style pointer, but a way to access one variable who's name is stored in another variable. As part of a spam-control measure, a certain public-facing form will have dummy rotating text fields and a hidden field that will describe which text field should be considered, like this: input type=text name=text_1 input type=text name=text_2 input type=text name=text_3 input type=hidden name=real_field value=text_2 As this will be a very general-purpose tool, a switch statement on the hidden field's value would not be appropriate here. Naturally, the situation will be much more complex and this is a non-obfuscated generalization of the HTML side of things which should describe the problem that I need to solve on the server side. Thanks in advance for any ideas. Some reading on this if you're interested: http://us2.php.net/manual/en/language.variables.variable.php You can also access array properties using variables if you like: $foo-some_prop = 'Hi there!'; $bar = 'some_prop'; echo $foo-$bar; Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] POST without POSTing
On Thu, 1 Oct 2009 00:16:27 -0400 Paul M Foster pa...@quillandmouse.com wrote: On Wed, Sep 30, 2009 at 11:36:55PM -0400, Daniel Brown wrote: On Wed, Sep 30, 2009 at 23:29, Paul M Foster pa...@quillandmouse.com wrote: I'm not sure how to do this. Please no exotic external libraries my shared hosting provider doesn't include. RTFM will be fine; just tell me which Fine Manual to Read. Nothing too exotic at all, Paul. Check out cURL: http://php.net/curl I was afraid you were going to say that, and I wasn't sure cURL was supported on that server. But I just loaded phpinfo on that server, and it is supported. However, assuming it *wasn't*, I've found the following example from a google search (thank goodness for google's hinting or I couldn't have found it): $fp = fsockopen(www.site.com, 80); fputs($fp, POST /script.php HTTP/1.0 Host: www.site.com Content-Length: 7 q=proxy); I don't know much about doing things this way. It appears that when done this way, the body must be separated by a newline, just like email. And it appears that the content-length of 7 indicates the length of the q=proxy string. Assuming I piled on a few other passed variables the same way as q, separated by newlines (and adjusted the Content-Length accordingly), would the above work? Are there liabilities to doing it this way? Paul Not separated by newlines; separated by ampersands. But otherwise, that's just raw HTTP 1.1 protocol. cURL and other tools might look a bit more complicated at first, but (assuming they're available) they do shield you from the raw protocol a bit. No real liability to doing it that way other than it's a bit more work. http://developers.sun.com/mobility/midp/ttips/HTTPPost/ Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] POST without POSTing
On Thu, 1 Oct 2009 00:24:41 -0400 Daniel Brown danbr...@php.net wrote: On Thu, Oct 1, 2009 at 00:16, Paul M Foster pa...@quillandmouse.com wrote: However, assuming it *wasn't*, I've found the following example from a google search (thank goodness for google's hinting or I couldn't have found it): $fp = fsockopen(www.site.com, 80); fputs($fp, POST /script.php HTTP/1.0 Host: www.site.com Content-Length: 7 q=proxy); I don't know much about doing things this way. It appears that when done this way, the body must be separated by a newline, just like email. And it appears that the content-length of 7 indicates the length of the q=proxy string. Assuming I piled on a few other passed variables the same way as q, separated by newlines (and adjusted the Content-Length accordingly), would the above work? Are there liabilities to doing it this way? Yes. Hosts are more likely to have cURL installed and available than fsockopen() or URL-based fopen() calls, so portability is greater with cURL. It's also a bit faster. Still, as you know, there's always more than one way to skin a cute, furry, delicious little kitten. I stand corrected on that point--in that way, yes, it would be a liability. Happily it's been so long since I've had to use that kind of host that I don't usually consider that a problem. But yes, if you're using free or low-end hosting then you might have to contend with that. Ugly, but true. Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Creating file name with $variable
On Mon, 21 Sep 2009 00:43:24 +0200 Ralph Deffke ralph_def...@yahoo.de wrote: Hi Haig, it would be better if u tell us what purpose u want to solf with this approuch. Its hard to understand for a prov why u want to create a filename .php .php files are scrips containing functions or classes, called/instantinated with parameters. why the hell u want to create a filename with these parameters? does this file excist? you can create 'dynamic code' in php, but u would never write it to a file! understand that that question is wierd and appears that ur concept is wild and realy sick. ralph_def...@yahoo.de Hi Ralph, First, please don't top-post. Second, please use complete words. 'u' is not a word. Third, I have no idea why you feel that such an knee-jerk reaction and abusive post would be helpful or useful. If you have nothing to add to the conversation, do not post. Haig Davis level...@gmail.com wrote in message news:46c80589-5a86-4c10-8f23-389a619bf...@gmail.com... Good Afternoon All, Thanks for the help with the checkbox issue the other day. Todays question: I want to create a filename.php from a variable more specifically the results if a mySQL query I.e. userID + orderNumber = filename. Is this possible? 'cause I've tried every option I can think of and am not winng. Thanks a ton Haig Hi Haig, Yes, this is possible; there is nothing special about creating such a file. Simply construct the filename as a string in normal PHP fashion, and then use that filename with file_put_contents(), fopen(), or similar, to create the file. It will be hard to help you further without an example (as short as you can make it) of what you are trying to do, and an explanation of how it's failing to do what you want it to do. Please post a short example of the code you have which is failing, and a longer explanation of exactly what you want to achieve, and perhaps we can explain how to make it work or suggest a better solution to your problem. Ralph did get one thing right, in that it's generally better to explain what you're trying to do instead of explaining how you're trying to do it. There are many ways to do almost any task, so it is possible that there is another way to do what you want which is simpler and less error-prone. Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question: Correcting MySQL's ID colomn when removing an entry
On Sun, 20 Sep 2009 12:07:39 +0430 Parham Doustdar parha...@gmail.com wrote: Hello there, I'm guessing that when a row in a MySQL table is removed, the ID colomns of the rows which come after that row are not changed. For example: 1 2 3 4 Now, if I want to remove the third rows, the ID colomn would be something like: 1 2 4 I was wondering if there was a way to fix it through a query, so I wouldn't have to use a for statement in PHP to fix it? Thanks! I'm not sure why you would want to do that--it would make things very hard to keep track of. Once an ID has been assigned to a set of data, that ID should not change. Perhaps if you explained the actual problem you're having, instead of how you're trying to solve it, it would be easier to offer a possible solution. There is likely a way to solve it which does not involve mangling the stored data. Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php.ini in cgi vs php.ini in cli
On Tue, 15 Sep 2009 10:11:56 -0400 Andres Gonzalez and...@packetstorm.com wrote: Lars, Thank you for your response. The function that raised this error is from my own extension module. I was not aware of phpinfo() and your suggestion to run it helped me resolve this issue. Turns out my CGI version is NOT using cgi/php.ini but is using apache2/php.ini instead. Thanks again for your help--you deserve a raise. :-) -Andres Hi Andres, Glad it worked! Regards, Torben Lars Torben Wilson wrote: On Mon, 14 Sep 2009 18:21:11 -0400 Andres Gonzalez and...@packetstorm.com wrote: In the php configurations directories /etc/php5, there are 2 subdirectories, one for cgi and one for cli. There is a php.ini file in each of these directories. What would cause a difference of behavior in these 2 environments with the php.ini exactly the same in each directory?? I have a command line script that consequently uses the cli version. This script works just fine in that it can access API function in modules that are loaded via cli/php.ini However, when executing in the cgi environment, I get a call to undefined function error even though my 2 php.ini files are exactly the same. Any idea what is causing this? thanks, -Andres Hi Andres, When asking this kind of question, it would be very helpful if you would tell us *which* function raised this error. My first thought is that you tried to call a function which was compiled in to the CLI version but not the CGI. What does phpinfo() show when run under each? Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] server name that the user agent used
Tom Worster wrote: On 9/13/09 10:24 PM, Tommy Pham tommy...@yahoo.com wrote: --- On Sun, 9/13/09, Tom Worster f...@thefsb.org wrote: From: Tom Worster f...@thefsb.org Subject: [PHP] server name that the user agent used To: PHP General List php-general@lists.php.net Date: Sunday, September 13, 2009, 8:21 PM when using apache with one vhost that responds to a few different hostnames, e.g. domain.org, y.domain.org, x.domain.org, let's say the vhost's server name is y.domain.org and the other two are aliases, is there a way in php to know which of these was used by the user agent to address the server? Did you see what comes up with php_info() for $_SERVER[SERVER_NAME] or $_SERVER[HTTP_HOST] ? SERVER_NAME returns whatever apache has as the vhost's configured server name. the php manual says of HTTP_HOST: Contents of the Host: header from the current request, if there is one. in which the last 4 words are a little off-putting. but: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23 i much more encouraging. the field is mandatory and should have what i'm looking for. it's absence is cause for a 400. casual testing (with a modern non-ie browser) seems to bear this out. so i'll try using that with fallback to my current techniques if i don't find a good value in HTTP_HOST. The reason that it might not be available is that PHP is not always running in a web context. $_SERVER['HOST_NAME'] would have no meaning, for instance, in the CLI SAPI. However, if running under a web SAPI, and if the web server provides the info, PHP will pass it on to its scripts. Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php.ini in cgi vs php.ini in cli
On Mon, 14 Sep 2009 18:21:11 -0400 Andres Gonzalez and...@packetstorm.com wrote: In the php configurations directories /etc/php5, there are 2 subdirectories, one for cgi and one for cli. There is a php.ini file in each of these directories. What would cause a difference of behavior in these 2 environments with the php.ini exactly the same in each directory?? I have a command line script that consequently uses the cli version. This script works just fine in that it can access API function in modules that are loaded via cli/php.ini However, when executing in the cgi environment, I get a call to undefined function error even though my 2 php.ini files are exactly the same. Any idea what is causing this? thanks, -Andres Hi Andres, When asking this kind of question, it would be very helpful if you would tell us *which* function raised this error. My first thought is that you tried to call a function which was compiled in to the CLI version but not the CGI. What does phpinfo() show when run under each? Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] get an object property
Tom Worster wrote: On 9/12/09 9:50 AM, Tom Worster f...@thefsb.org wrote: On 9/12/09 1:32 AM, Lars Torben Wilson tor...@php.net wrote: Tom Worster wrote: if i have an expression that evaluates to an object, the return value from a function, say, and i only want the value of one of the objects properties, is there a tidy way to get it without setting another variable? to illustrate, here's something that doesn't work, but it would be convenient if it did: $o = array( (object) array('a'=1), (object) array('a'=2) ); if ( end($o)-a 1 ) { // can't use - like this! ... } What version of PHP are you using? Your example should work. Torben 5.2.9. what version does it work in? i shamefully beg your pardon, lars. i was sure i tested the example but it's clear to me now i either didn't or i made a mistake. end($o)-a IS php syntax! so - may follow a function (or method, i guess) call. No need for apologies. :) but let me give you a more different example: $a and $b are normally both objects, each with various members including a prop q, but sometimes $a is false. i want the q of $a if $a isn't false, otherwise that of $b. ($a ? $a : $b)-q // is not php, afaik before you suggest one, i know there are simple workarounds. You're right, that isn't PHP syntax. One workaround that came to mind which does a similar thing (although using a different mechanism) is this: ${$a ? 'a' : 'b'}-q but mine is a theoretical question about syntax, not a practical one. i'm exploring php's syntactic constraints on the - operator in contrast to, say, the + or . operators. and in contrast to other languages. I can respect that. This kind of exploration is often quite illuminating. for example, the . in js seems more generally allowed than - (or, for that matter, []) in php. programmers (especially using jquery) are familiar with using . after an expression that evaluates to an object, e.g. body p id=thepara class=top x23 indentMy x class number is span id=num/span/p div id=mandatory style=border: solid red 1px/div script type=text/javascript document.getElementById('num').innerText = ( ( document.getElementById('optional') || document.getElementById('mandatory') ).appendChild(document.getElementById('thepara')) .className.match(/x(\d+)/) || [0,'absent'] )[1] /script /body which shows . after objects, method calls and expressions (as well as the [] operator applied to an expression). do we just live without in phpville or am i missing something? We live without, just like we live without $foo =~ s/bar/baz/i; . . .and without: cout Hello world endl; . . .and without: #define FOO(bar, baz) ((bar) * (baz)) . . .and so on. It's just syntax from other languages which isn't part of the PHP syntax. and while i'm at it, and using my original error, how come... function o() { return (object) array('q'=7); } echo o()-q; // is ok syntax, but function a() { return array('q'=5); } echo a()['q']; // isn't? I'm afraid I can't answer that right now--it does perhaps seem inconsistent at first glance, although I can't say I've ever missed it or felt that using syntax like that would make my life any better. Maybe it would. Then again, I can also see an argument being made for allowing the object syntax but not the array syntax: in the case of objects, you can have a clean class declaration which is pretty much self-documenting, and later users of the class can have a clear idea of which properties are available and which are not, and they can thus be sure that o()-q will not result in uninitialized property problems. Using the array syntax you could never be sure that the index requested actually exists. Of course, this holds true only for people like me who don't really like the idea of creating objects on the fly in PHP unless there's a very good reason to. Usually in PHP such tasks are better handled by arrays anyway. This is of course just random thinking and perhaps it's just because nobody has added that syntax to the scanner. :) Anyway, good luck with your language comparison. Like I said before, that kind of thing is often fun (and always instructional). Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] get an object property
Tom Worster wrote: On 9/13/09 3:21 AM, Lars Torben Wilson tor...@php.net wrote: On 9/12/09 9:50 AM, Tom Worster f...@thefsb.org wrote: but let me give you a more different example: $a and $b are normally both objects, each with various members including a prop q, but sometimes $a is false. i want the q of $a if $a isn't false, otherwise that of $b. ($a ? $a : $b)-q // is not php, afaik before you suggest one, i know there are simple workarounds. You're right, that isn't PHP syntax. One workaround that came to mind which does a similar thing (although using a different mechanism) is this: ${$a ? 'a' : 'b'}-q i would not have thought of that. interesting... and while i'm at it, and using my original error, how come... function o() { return (object) array('q'=7); } echo o()-q; // is ok syntax, but function a() { return array('q'=5); } echo a()['q']; // isn't? I'm afraid I can't answer that right now--it does perhaps seem inconsistent at first glance, although I can't say I've ever missed it or felt that using syntax like that would make my life any better. Maybe it would. Then again, I can also see an argument being made for allowing the object syntax but not the array syntax: in the case of objects, you can have a clean class declaration which is pretty much self-documenting, and later users of the class can have a clear idea of which properties are available and which are not, and they can thus be sure that o()-q will not result in uninitialized property problems. Using the array syntax you could never be sure that the index requested actually exists. Of course, this holds true only for people like me who don't really like the idea of creating objects on the fly in PHP unless there's a very good reason to. Usually in PHP such tasks are better handled by arrays anyway. the dbms abstraction library i use delivers rows, by default, as objects. so i commonly handle dynamically generated data in the form of objects, though it's not my code generating those objects. i think that's one reasons why i often find i would use objects as data structures. and because i find the dynamic objects in js convenient. Yeah. . .never been a fan of the libs which return objects, although such a model does perhaps have its uses. but i think you're preference reflects more closely was probably the concept of php's version of oop: an object is an instances of a static class. Yes, I'd say the same thing, except I'd replace the term 'static' with 'declared'. If an object is created on the fly, in someone else's code, and I have to maintain that code, then either that code must be well-documented or I have to go on a hunt through the source code to find out what might be available within that object. Not my idea of fun. Convenient for the original coder, perhaps, especially if they come from an automatic model background such as Javascript. And maybe one day I'll come to love it. So far I haven't seen enough of a benefit to convince me that it's worth the long-term maintenance headache it can (note that I say can, not does) cause. in any case, now that i've confirmed that i'm not merely unaware of the features i was hunting for, and that they don't exist by design, i can perhaps move on. on a related note, way back when xml was ascendant as the most exciting new technology to hit the net since java, i was not impressed. what a horrid syntax for specifying and communicating data, i would argue. why not use the syntax from some sensible programming language instead? js, for example? easy to parse, less overhead, human readable (i find xml hard to read), etc. then eventually json happened, without all the hype and fanfare, just doing the job very conveniently. i love it. I also never found myself sold on the XML everywhere philosophy which seemed to spring up during its first few years. I have found it useful for certain things--usually involving documents. :) It's awesome for technical documentation such as working on the PHP manual; I've used it when writing books; and XML and the DOM can be a great help when constructing automatically validated XHTML. But there are also many other things which people insisted it would be perfect for which just end up being a waste of cycles and memory. It's a good tool for some tasks but completely ill-suited for others IMHO. I like the idea of json when working with Javascript. Years ago (before var_export()) I wrote something very similar to var_export() which would write out a human-readable and directly PHP-parseable string for structured data. Sort of like. . .er. . .pson (*cough*). ;) and to make that comment vaguely php related, i now use json to encode structured data that i want to write to the php error log. Interesting. For something like that I would just use var_export() and skip the overhead of parsing json back into PHP if I needed to do that. I'd use json when using Javascript
Re: [PHP] get an object property
Tom Worster wrote: if i have an expression that evaluates to an object, the return value from a function, say, and i only want the value of one of the objects properties, is there a tidy way to get it without setting another variable? to illustrate, here's something that doesn't work, but it would be convenient if it did: $o = array( (object) array('a'=1), (object) array('a'=2) ); if ( end($o)-a 1 ) { // can't use - like this! ... } What version of PHP are you using? Your example should work. Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] safe_mode and inclusion of files don't work as documented
2009/8/31 Nico Sabbi nsa...@officinedigitali.it: Lars Torben Wilson ha scritto: Hi Nico, First the obligatory safe_mode is deprecated and not recommended speech. . .but I guess you've already seen that in the docs and decided to use it anyway. I read it, but I don't know if I have to interpret it as php6 wil only work in safe mode or safe_mode is a bad idea ;-) Safe mode is a bad idea. :) It's not safe; it may only have the effect of making you think you're safe. If you have a particular reason to use it then maybe it's OK, but just be aware that it will not exist in future versions of PHP and relying on it is not a good idea. Security, unfortunately, is not as simple as toggling a configuration variable. What does the script do if you turn off safe_mode? it works perfectly Can you post a simple script which demonstrates your problem (the whole script, hopefully as short as you can make it) but which works fine with safe_mode off? Also it would be helpful if you can include the output of phpinfo() both with safe_mode on and with safe_mode off. Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] safe_mode and inclusion of files don't work as documented
2009/8/28 Nico Sabbi nsa...@officinedigitali.it: Hi, I'm testing one of my sites in safe_mode, but I'm experiencing some strangeness that is not documented. The settings are: in php.ini: include_path = .:/server/home/apache/php4/:/var/php/5.2/pear/:/usr/php/lib/ezcomponents-2008.2.2/ in the virtualhost config: php_admin_value safe_mode On php_admin_value safe_mode_include_dir /server/home/nsabbi:/server/home/apache/php4:.:.. The files belong entirely to apache:apache, the user who is running apache. The problem is: *Fatal error*: require_once() [function.require http://nsabbi/login/function.require]: Failed opening required '../include.php' (include_path='.:..:/server/home/apache/php4/:/var/php/5.2/pear/:/usr/php/lib/ezcomponents-2008.2.2/') in */server/home/nsabbi/nb4/login/index.php* on line *3 How is it that i can't include files in .. Hi Nico, First the obligatory safe_mode is deprecated and not recommended speech. . .but I guess you've already seen that in the docs and decided to use it anyway. What does the script do if you turn off safe_mode? btw, can I redefine the include_path in safe mode? Yes. Thanks, Nico Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: page works on public web site, but not on my computer
2009/8/27 mike bode mikebo...@hotmail.com: I understand, but that's not an option. I am not interested in getting into a Linux vs. Windows fight here, let's just say that I am stuck with Windows. Now, somthing's gotta be seriously wrong here. I have tried now 4 or 5 different scripts for the photo gallery that I am trying to implement and NONE of them has worked. I have enabled all extensions and loaded all modules in Apache and php -- still nothing. I can't believe that the Apache Society out there simply ignores the 80% or so that use Windows. Can anybody point me to a group that deals with Apache (PHP) on Windows? Thanks. mike Hi Mike, First off, it's hard to say whether your problem actually is OS-related or whether it's due to a system misconfiguration or what. That said, while the majority of desktop users may still use Windows, I don't think you'll find that Windows or Vista make up a very large percentage of Apache's target market at all. Anyway, have you tried running just a script containing only ?php phpinfo(); ? ? This should at least give you an indication of whether the installation is working at all. I haven't gone back over both threads on this so if you've already tried this and it worked, please ignore this. :) Cheers, Torben Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1251290333.27899.27.ca...@localhost... On Wed, 2009-08-26 at 08:27 -0400, Bob McConnell wrote: I recommend you start by replacing Vista. There are so many problems with it that Microsoft is rushing to ship a replacement as soon as possible. It remains to be seen whether Windows 7 is a real fix or merely more of the same problems. I am not aware of any serious developers writing code specifically for Vista. We only test our products on it enough to decide if we will support each product on that OS. If they don't work out of the box, we don't support them nor recommend our clients install them on Vista. There are no copies of Vista installed in the company outside of the ESX servers used for testing. I would recommend Red Hat as the replacement. Bob McConnell -Original Message- From: mike bode [mailto:mikebo...@hotmail.com] Sent: Tuesday, August 25, 2009 11:41 PM To: php-general@lists.php.net Subject: [PHP] Re: page works on public web site, but not on my computer I just de-installed, then re-installed MySQL, Apache and PHP 5.3. No changes. The script does not work on my computer. Now I get in addition to the error message below this: [Tue Aug 25 21:29:11 2009] [error] [client 127.0.0.1] PHP Deprecated: Function eregi() is deprecated in C:\\webdev\\rmv3\\album\\getalbumpics.php on line 11, referer: http://localhost/album.php Don't know if those warnings would stop the execution of the php script. mike bode mikebo...@hotmail.com wrote in message news:99.f2.08117.ccf74...@pb1.pair.com... I have posted the question in another thread a bit down, but only buried within the thread, so please excuse me when I ask again. I want to use some PHP code from a web site (http://www.dynamicdrive.com/dynamicindex4/php-photoalbum.htm), and I am following their instruction how to implement it. I was not able to get it to work. Then I uploaded the code to a server, and lo and behold, it does work on the server. On the public site you see thumbnails of images (never mind the junk above them), when I run the SAME html and php code on my omputer, I get a blank white page. The error log has several entries, but they are all warnings: [Tue Aug 25 18:12:00 2009] [error] [client 127.0.0.1] PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Denver' for '-6.0/DST' instead in C:\\webdev\\rmv3\\album\\getalbumpics.php on line 11, referer: http://localhost/album.htm (this error is repeated for as many images I have in the directory that the php script is reading). Between php.ini, httpd.conf, and Windows Vista, I can't figure out where to start to diagnose this, and how. Anybody out there who can give me a pointer on how to roubleshoot this issue? I am almost ready to throw in the towel and either start from scratch (although this is alrady the second time that I have uninstalled and re-installed everything), or simply forget about php altogether. that would be a shame, though... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I'll second that. I don't use Windows myself anymore for anything except World of Warcraft, but my little time spent using Vista has left me wanting to do violence! You can't go too wrong with using a Linux OS as your development
Re: [PHP] How to output a NULL field?
2009/8/25 David Stoltz dsto...@shh.org: if(empty($rs-Fields(22))){ Hi David, You cannot call empty() on a function or class method like that. From the manual: Note: empty() only checks variables as anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). - http://www.php.net/empty You should assign the result of $rs-Fields(22) to a variable before calling empty() on it, or use a class variable access to check it, or check it first within the class and have Fields() return a suitable value if needed. Regards, Torben $q4 = ''; }else{ $q4 = ''.$rs-Fields(22); } Still produces errors, whether using empty or is_nullwith single quotes ??? -Original Message- From: Bastien Koert [mailto:phps...@gmail.com] Sent: Tuesday, August 25, 2009 2:17 PM To: David Stoltz Cc: php-general@lists.php.net Subject: Re: [PHP] How to output a NULL field? On Tue, Aug 25, 2009 at 2:00 PM, David Stoltzdsto...@shh.org wrote: $rs-Fields(22) equals a NULL in the database My Code: if(empty($rs-Fields(22))){ $q4 = ; }else{ $q4 = $rs-Fields(22); } Produces this error: Fatal error: Can't use method return value in write context in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 32 Line 32 is the if line... If I switch the code to (using is_null): if(is_null($rs-Fields(22))){ $q4 = ; }else{ $q4 = $rs-Fields(22); } It produces this error: Catchable fatal error: Object of class variant could not be converted to string in D:\Inetpub\wwwroot\evaluations\lookup2.php on line 196 Line 196 is: ?php echo $q4;? What am I doing wrong? Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php $q4 = '' . $rs-Fields(22); Note that it's two single quotes -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: page works on public web site, but not on my computer
2009/8/25 mike bode mikebo...@hotmail.com: I just de-installed, then re-installed MySQL, Apache and PHP 5.3. No changes. The script does not work on my computer. Now I get in addition to the error message below this: [Tue Aug 25 21:29:11 2009] [error] [client 127.0.0.1] PHP Deprecated: Function eregi() is deprecated in C:\\webdev\\rmv3\\album\\getalbumpics.php on line 11, referer: http://localhost/album.php Hi Mike, No, those messages don't indicate anything which would cause PHP to fail or abort. Do you see anything different if you change error_reporting to error_reporting = E_ALL, display_errors = On, and display_startup_errors = On in php.ini? (Note: if you do turn on display_errors and display_startup_errors, be sure to turn them off again before making your page available to the public). Are you using the PHP Apache module or fastcgi or some other method? Torben Don't know if those warnings would stop the execution of the php script. mike bode mikebo...@hotmail.com wrote in message news:99.f2.08117.ccf74...@pb1.pair.com... I have posted the question in another thread a bit down, but only buried within the thread, so please excuse me when I ask again. I want to use some PHP code from a web site (http://www.dynamicdrive.com/dynamicindex4/php-photoalbum.htm), and I am following their instruction how to implement it. I was not able to get it to work. Then I uploaded the code to a server, and lo and behold, it does work on the server. On the public site you see thumbnails of images (never mind the junk above them), when I run the SAME html and php code on my omputer, I get a blank white page. The error log has several entries, but they are all warnings: [Tue Aug 25 18:12:00 2009] [error] [client 127.0.0.1] PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Denver' for '-6.0/DST' instead in C:\\webdev\\rmv3\\album\\getalbumpics.php on line 11, referer: http://localhost/album.htm (this error is repeated for as many images I have in the directory that the php script is reading). Between php.ini, httpd.conf, and Windows Vista, I can't figure out where to start to diagnose this, and how. Anybody out there who can give me a pointer on how to roubleshoot this issue? I am almost ready to throw in the towel and either start from scratch (although this is alrady the second time that I have uninstalled and re-installed everything), or simply forget about php altogether. that would be a shame, though... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What if this code is right ? It worked perfectly for years!!
2009/8/24 Chris Carter chandan9sha...@yahoo.com: Hi, The code below actually takes input from a web form and sends the fields captured in an email. It used to work quite well since past few years. It has stopped now. I used Google's mail servers (google.com/a/website.com) ? $fName = $_REQUEST['fName'] ; $emailid = $_REQUEST['emailid'] ; $number = $_REQUEST['number'] ; $message = $_REQUEST['message'] ; mail( ch...@gmail.com, $number, $message, From: $emailid ); header( Location: http://www.thankyou.com/thankYouContact.php; ); ? This is the simplest one, how could it simply stop? Any help would be appreciated, I have already lost 148 queries that came through this form. Thanks in advance, Chris Hi Chris, More information would be very helpful. In exactly what way is it failing? Blank page? Apparently normal operation, except the email isn't being sent? Error messages? Log messages? etc. . . One possibility is that the server config has changed to no longer allow short open tags. This is easy to check for by simply replacing '?' with ?php' on the first line. There are of course other possibilities but without knowing how it's failing, any guesses would just be shots in the dark. Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What if this code is right ? It worked perfectly for years!!
2009/8/24 Paul M Foster pa...@quillandmouse.com: On Mon, Aug 24, 2009 at 10:37:11AM -0700, Chris Carter wrote: Is there any alternative method to do this !!! Sending email through PHP? Sure. You can use a class like PHPMailer rather than the built-in mail() function. But it's not going to matter if the problem is at the mail server, etc. Paul Agreed. Rather than just trying things willy-nilly, the OP should attempt to determine what the actual problem is. This gives a much greater chance of solving it. Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] daemon without pcntl_fork
2009/8/20 Jim Lucas li...@cmsws.com: Lars Torben Wilson wrote: 2009/8/19 Per Jessen p...@computer.org: Jim Lucas wrote: [snip] I probably wouldn't have chosen PHP for the first one, but there's no reason it shouldn't work. For the second one, did you mean to write serial port? That's a bit of a different animal, I'm not sure how far you'll get with php. Here is what I have come up with so far. Looks to satisfying my needs: tms_daemon [snip] # END OF SCRIPT Looks good to me. It'll certainly do the job. /Per I agree with Per on all points--I probably wouldn't choose PHP as a first choice for the first task, but the startup script you have shown looks like a bog-standard startup script and should serve you well. I haven't really gone over it with a fine-toothed comb though. Typos etc. are still up to to you. :) Of course, the whole thing depends on how tms_daemon behaves, but the startup script looks OK. Can you explain in a bit more detail exactly what the second part (the serial-network data logger) needs to do? I've written similar daemons in C but not PHP--when I've needed to get something like that going with a PHP script, I've used ser2net (which I linked to in an earlier post) and been quite happy. Maybe you don't even have to do the hard work yourself (or buy extra hardware to do it for you). Cheers, Torben As for the second project, I asked about it in the previous thread about the SMDR/CDR processor. http://www.nabble.com/SMDR-CDR-daemon-processor-td25014822.html Sorry, missed that thread. Basically, I need to have a process that collects data via serial (USB|RS323), connects to a remote port, or listens and receives data from the PBX pushing it. The most common is the RS232 serial connection. Thats why I need to be able to listen on the local RS232 port for data coming from the PBX system. What I have built so far can connect to a remote machine, via a TCP/IP connection, and wait for data to be push out the specified TCP port. I haven't done it yet, but I know that I can easily build, using a different project as a base, the version that would connect to a local TCP/IP IP:PORT and wait for a PBX to send the data to that IP:PORT. After the data has been received, the process flow will be the same with all three methods. Parse it, sanitize it, store it. Hopefully that explains a little more. Jim In short, are you looking for a program which listens on a serial port and a network port at the same time, and places any data received from either into a database? Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array() returns something weird
2009/8/22 Szczepan Hołyszewski webmas...@strefarytmu.pl: Hello! I am almost certain I am hitting some kind of bug. All of a sudden, array() stops returning an empty array and starts returning something weird. The weird thing behaves as NULL in most circumstances (e.g. gettype() says NULL), except: $foo=array(); // -- weird thing returned $foo[]=bar; causes Fatal error: [] operator not supported for strings, which is different from the regular behavior of: Hi there, Without seeing the actual code, it's hard to say what the problem is. However, I'd be pretty surprised if you've actually run into a bug in PHP--I would first suspect a bug in your code. No offense intended--that's just how it usually plays out. :) What it looks like to me is that something is causing $foo to be a string before the '$foo[] = bar;' line is encountered. What do you get if you put a gettype($foo); just before that line? $foo=null; $foo[]=bar; // -- $foo simply becomes an array The problem is not limited to one place in code, and indeed before the fatal caused by append-assignment I get several warnings like array_diff_key(): Argument #1 is not an array, where the offending argument receives a result of array(). This would appear to support my suspicion, but try inserting the gettype($foo) (or better, var_export($foo);) just before one of the lines which triggers the error, and post the results. Can you post the code in a .zip file or online somewhere? If not, that's cool, but it will probably make it harder to help you track it down if you can't. Regards, Torben The effect is not random, i.e. it always breaks identically when the same script processes the same data. However I was so far unable to create a minimal test case that triggers the bug. My script is rather involved, and here are some things it uses: - Exceptions - DOM to-fro SimpleXML - lots of multi-level output buffering Disabling Zend Optimizer doesn't help. Disabling Zend Memory Manager is apparently impossible. Memory usage is below 10MB out of 128MB limit. Any similar experiences? Ideas what to check for? Workarounds? From phpinfo(): PHP Version: 5.2.9 (can't easily upgrade - shared host) System: FreeBSD 7.1-RELEASE-p4 FreeBSD 7.1-RELEASE-p4 #0: Wed Apr 15 15:48:43 UTC 2009 amd64 Configure Command: './configure' '--enable-bcmath' '--enable-calendar' '--enable-dbase' '--enable- exif' '--enable-fastcgi' '--enable-force-cgi-redirect' '--enable-ftp' '-- enable-gd-native-ttf' '--enable-libxml' '--enable-magic-quotes' '--enable- maintainer-zts' '--enable-mbstring' '--enable-pdo=shared' '--enable-safe-mode' '--enable-soap' '--enable-sockets' '--enable-ucd-snmp-hack' '--enable-wddx' '--enable-zend-multibyte' '--enable-zip' '--prefix=/usr' '--with-bz2' '--with- curl=/opt/curlssl/' '--with-curlwrappers' '--with-freetype-dir=/usr/local' '-- with-gd' '--with-gettext' '--with-imap=/opt/php_with_imap_client/' '--with- imap-ssl=/usr/local' '--with-jpeg-dir=/usr/local' '--with-libexpat- dir=/usr/local' '--with-libxml-dir=/opt/xml2' '--with-libxml-dir=/opt/xml2/' '--with-mcrypt=/opt/libmcrypt/' '--with-mhash=/opt/mhash/' '--with-mime-magic' '--with-mysql=/usr/local' '--with-mysql-sock=/tmp/mysql.sock' '--with- mysqli=/usr/local/bin/mysql_config' '--with-openssl=/usr/local' '--with- openssl-dir=/usr/local' '--with-pdo-mysql=shared' '--with-pdo-sqlite=shared' '--with-pgsql=/usr/local' '--with-pic' '--with-png-dir=/usr/local' '--with- pspell' '--with-snmp' '--with-sqlite=shared' '--with-tidy=/opt/tidy/' '--with- ttf' '--with-xmlrpc' '--with-xpm-dir=/usr/local' '--with-xsl=/opt/xslt/' '-- with-zlib' '--with-zlib-dir=/usr' Thanks in advance, Szczepan Holyszewski -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array() returns something weird
2009/8/22 Szczepan Hołyszewski webmas...@strefarytmu.pl: What it looks like to me is that something is causing $foo to be a string before the '$foo[] = bar;' line is encountered. What do you get if you put a gettype($foo); just before that line? $foo=null; $foo[]=bar; // -- $foo simply becomes an array NULL. That is the problem. I _did_ put a gettype($foo) before the actual line. OK, here are exact four lines of my code: $ret=array(); foreach(self::$_allowed as $r = $a) if ($a) $ret[]=$r; As you can see, there is not a shred of a chance for $ret to become something other than empty array between initialization and the last line in the above snippet which causes the fatal errror. There's no __staticGet in 5.2.9, so self::$_allowed cannot have side effects. Secondly, the above code starts failing after it has executed successfully dozens of times (and yes, the last line _does_ get executed; in fact self:: $_allowed contains configuration information that doesn't change at runtime). Thirdly... The problem is not limited to one place in code, and indeed before the fatal caused by append-assignment I get several warnings like array_diff_key(): Argument #1 is not an array, where the offending argument receives a result of array(). This would appear to support my suspicion, but try inserting the gettype($foo) (or better, var_export($foo);) just before one of the lines which triggers the error, and post the results. No, I don't think it supports your suspicion. Conversely, it indicates that once array() returns a strangelet, it starts returning strangelets all over the place. Initially it only triggers warnings but eventually one of the returned strangelets is used in a way that triggers a fatal error. As per your request: //at the beginning of the script: $GLOBALS['offending_line_execution_count']=0; // /srv/home/[munged]/public_html/scripts/common.php line 161 and on // instrumented as per your request: public static function GetAllowed() { if (debug_mode()) echo ++$GLOBALS['offending_line_execution_count'].br/; $ret=array(); if (debug_mode()) echo var_export($ret).br/; foreach(self::$_allowed as $r = $a) if ($a) $ret[]=$r; if (self::$_allowEmpty) $ret[]=; return $ret; } Output tail: --- 28 array ( ) 29 array ( ) 30 array ( ) 31 array ( ) 32 array ( ) Warning: array_diff_key() [function.array-diff-key]: Argument #1 is not an array in /srv/home/u80959ue/public_html/v3/scripts/SimpliciText.php on line 350 Warning: Invalid argument supplied for foreach() in /srv/home/u80959ue/public_html/v3/scripts/SimpliciText.php on line 351 Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /srv/home/u80959ue/public_html/v3/scripts/SimpliciText.php on line 357 Warning: Invalid argument supplied for foreach() in /srv/home/u80959ue/public_html/scripts/common.php on line 28 Warning: Invalid argument supplied for foreach() in /srv/home/u80959ue/public_html/scripts/common.php on line 28 Warning: Invalid argument supplied for foreach() in /srv/home/u80959ue/public_html/scripts/common.php on line 28 33 NULL Fatal error: [] operator not supported for strings in /srv/home/u80959ue/public_html/scripts/common.php on line 168 -- The warnings come from other uses of array(). But wait! There is this invocation of debug_mode() between initialization of $ret var_export. Let's factor it out to be safe: $debugmode=debug_mode(); if ($debugmode) echo ++$GLOBALS['offending_line_execution_count'].br/; $ret=array(); if ($debugmode) echo var_export($ret).br/; And now the output ends with: Warning: Invalid argument supplied for foreach() in /srv/home/u80959ue/public_html/scripts/common.php on line 28 33 Fatal error: [] operator not supported for strings in /srv/home/u80959ue/public_html/scripts/common.php on line 169 No NULL after 33? What the heck is going on? Does array() now return something that var_exports to an empty string, or does it destroy local variables? Let's see: if ($debugmode) echo var_export($ret).br/; else echo WTF?!?!?br/; And the output: Warning: Invalid argument supplied for foreach() in /srv/home/u80959ue/public_html/scripts/common.php on line 28 33 WTF?!?!? Fatal error: [] operator not supported for strings in /srv/home/u80959ue/public_html/scripts/common.php on line 169 --- Indeed, the use of
Re: [PHP] array() returns something weird
2009/8/22 Szczepan Hołyszewski webmas...@strefarytmu.pl: Hm. . .it does look odd. Searching the bugs database at http://bugs.php.net does turn up one other report (at http://bugs.php.net/bug.php?id=47870 ) of array() returning NULL in certain hard-to-duplicate circumstances on FreeBSD, Yes, I found it even before posting here, but I wasn't sure whether to file a new report or comment under this one. If your intuition is that these bugs are related, then I will do the latter. Thank you for your attention. Well, the only things I'm basing my suspicion on are the nature of the problem, the OS similarity and the fact that it seems to be difficult to reproduce the problem reliably. The major problem with this guess is that the original bug report does state that the bug did not show up under 5.2. I don't suppose you have a development environment on another machine where you can test another version of PHP? Assuming you mean a FreeBSD environment, nope :( but I will try on Linux tomorrow. OK. I do think (as I'm sure you know) that the best test would be in a matching environment (since the result was reported to be different under Linux for that bug), but of course that's not always realistic. Regards, Szczepan Holyszewski I hope your problem can be resolved. If it does turn out to be a bug in PHP I hope that will be enough to convince your host to upgrade. Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is there limitation for switch case: argument's value?
2009/8/22 Keith survivor_...@hotmail.com: Thanks! Torben. I got the point now and it works! :-) I'm doing this because the statements of each cases is quite long, and I wish to have minimum coding without repetition. Hi Keith, Glad it works! I'm not sure how inverting the case statement helps you minimize the code in each case. As both I and Adam showed, you can do the same thing more efficiently (and IMHO much more readably) like this: switch ($sum) { case 8: break; case 7: case 6: break; case 2: case 1: break; case 0: break; default: break; } Lars Torben Wilson larstor...@gmail.com wrote in message news:36d4833b0908202323p3c858b5fn6a1d6775aa7f8...@mail.gmail.com... 2009/8/20 Keith survivor_...@hotmail.com: Hi, I encounter a funny limitation here with switch case as below: The value for $sum is worked as expected for 1 to 8, but not for 0. When the $sum=0, the first case will be return, which is sum=8. Is there any limitation / rules for switch case? Thanks for advice! Keith Hi Keith, Try replacing 'switch($sum)' with 'switch(true)'. Note that unless you have very good reasons for using a switch statement like this, and know exactly why you're doing it, it's often better just to use it in the normal fashion. i.e.: switch ($sum) { case 8: break; case 7: case 6: break; case 2: case 1: break; case 0: break; default: break; } Some people like the syntax you've presented but honestly, there's usually a better way to do it. This is also somewhat faster too, although you may only notice the difference in very tight loops where you're counting every nanosecond. Regards, Torben $sum=0; switch($sum) { case ($sum==8): echo sum=8; break; case ($sum==7 || $sum==6): echo sum=7 or 6; break; case ($sum==2 || $sum==1): echo sum=2 or 1; break; case 0: echo sum=0; break; default: echo sum=3/4/5; break; } -- 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 General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is there limitation for switch case: argument's value?
Aargh. Slipped on the trigger there--premature Send. See below for what I meant to send: 2009/8/22 Lars Torben Wilson tor...@php.net: 2009/8/22 Keith survivor_...@hotmail.com: Thanks! Torben. I got the point now and it works! :-) I'm doing this because the statements of each cases is quite long, and I wish to have minimum coding without repetition. Hi Keith, Glad it works! I'm not sure how inverting the case statement helps you minimize the code in each case. As both I and Adam showed, you can do the same thing more efficiently (and IMHO more readably) like this: switch ($sum) { case 8: echo The sum is 8; break; case 7: case 6: echo The sum is 7 or 6; break; case 2: case 1: echo The sum is 2 or 1; break; case 0: echo The sum is 0; break; default: echo The sum is 3, 4, or 5; break; } And if the code is getting so long that it's getting unwieldy, you might want to look into breaking it out into separate functions. Anyway, it's not a huge thing; personally though I feel that it's a syntax that if ever used, should only be used for very good reasons. Most of the uses I've seen of it, however, fall into the overly clever category and add nothing in the end to the quality of the code. That's totally a judgement call on my part, of course. :) Again, glad it works, and keep on coding! Regards, Torben Lars Torben Wilson larstor...@gmail.com wrote in message news:36d4833b0908202323p3c858b5fn6a1d6775aa7f8...@mail.gmail.com... 2009/8/20 Keith survivor_...@hotmail.com: Hi, I encounter a funny limitation here with switch case as below: The value for $sum is worked as expected for 1 to 8, but not for 0. When the $sum=0, the first case will be return, which is sum=8. Is there any limitation / rules for switch case? Thanks for advice! Keith Hi Keith, Try replacing 'switch($sum)' with 'switch(true)'. Note that unless you have very good reasons for using a switch statement like this, and know exactly why you're doing it, it's often better just to use it in the normal fashion. i.e.: switch ($sum) { case 8: break; case 7: case 6: break; case 2: case 1: break; case 0: break; default: break; } Some people like the syntax you've presented but honestly, there's usually a better way to do it. This is also somewhat faster too, although you may only notice the difference in very tight loops where you're counting every nanosecond. Regards, Torben $sum=0; switch($sum) { case ($sum==8): echo sum=8; break; case ($sum==7 || $sum==6): echo sum=7 or 6; break; case ($sum==2 || $sum==1): echo sum=2 or 1; break; case 0: echo sum=0; break; default: echo sum=3/4/5; break; } -- 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 General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is there limitation for switch case: argument's value?
2009/8/20 Keith survivor_...@hotmail.com: Hi, I encounter a funny limitation here with switch case as below: The value for $sum is worked as expected for 1 to 8, but not for 0. When the $sum=0, the first case will be return, which is sum=8. Is there any limitation / rules for switch case? Thanks for advice! Keith Hi Keith, Try replacing 'switch($sum)' with 'switch(true)'. Note that unless you have very good reasons for using a switch statement like this, and know exactly why you're doing it, it's often better just to use it in the normal fashion. i.e.: switch ($sum) { case 8: break; case 7: case 6: break; case 2: case 1: break; case 0: break; default: break; } Some people like the syntax you've presented but honestly, there's usually a better way to do it. This is also somewhat faster too, although you may only notice the difference in very tight loops where you're counting every nanosecond. Regards, Torben $sum=0; switch($sum) { case ($sum==8): echo sum=8; break; case ($sum==7 || $sum==6): echo sum=7 or 6; break; case ($sum==2 || $sum==1): echo sum=2 or 1; break; case 0: echo sum=0; break; default: echo sum=3/4/5; break; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] daemon without pcntl_fork
2009/8/19 Per Jessen p...@computer.org: Jim Lucas wrote: [snip] I probably wouldn't have chosen PHP for the first one, but there's no reason it shouldn't work. For the second one, did you mean to write serial port? That's a bit of a different animal, I'm not sure how far you'll get with php. Here is what I have come up with so far. Looks to satisfying my needs: tms_daemon [snip] # END OF SCRIPT Looks good to me. It'll certainly do the job. /Per I agree with Per on all points--I probably wouldn't choose PHP as a first choice for the first task, but the startup script you have shown looks like a bog-standard startup script and should serve you well. I haven't really gone over it with a fine-toothed comb though. Typos etc. are still up to to you. :) Of course, the whole thing depends on how tms_daemon behaves, but the startup script looks OK. Can you explain in a bit more detail exactly what the second part (the serial-network data logger) needs to do? I've written similar daemons in C but not PHP--when I've needed to get something like that going with a PHP script, I've used ser2net (which I linked to in an earlier post) and been quite happy. Maybe you don't even have to do the hard work yourself (or buy extra hardware to do it for you). Cheers, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] daemon without pcntl_fork
2009/8/17 Jim Lucas li...@cmsws.com: I want this to be a system that works out of the box. For the most part. I am expecting to have phone system vendors and low-level IT personal trying to install this thing. I don't want to have to field tons of questions on How do I compile this p#*(_fork thing into PHP? Anyways, could I compile a customer build of the php cli and include that into my package? Certainly! You haven't mentioned how you intend to package it though, so that Certainly! does come with some caveats. But including pcntl is no different from including any other extension--in fact, the chances of the target system being able to deal with it are greater, if anything. If you compile it in, it'll be there. However, if it's going to be limited to the point that you're including binaries only for a specific platform, then A) compiling it in is no big deal, and B) perhaps you should be looking at how you're packaging the thing. Would things be statically links to the binary. ie every thing it needed would be built into it. Or would I have to rip out as much as possible to make sure that it was compatible with a persons system? Not sure what you mean by that, but if the target audience isn't competent to deal with this, then your support calls are going to hurt either way. :) Which is why I said perhaps you should be looking at how you're packaging it. Anything you compile on one system is going to require some forethought in order to make it broadly applicable on other systems, but any relevant system should be able to handle the basics such as process control. Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] daemon without pcntl_fork
2009/8/18 Per Jessen p...@computer.org: Jim Lucas wrote: Does anybody know how to use PHP as a daemon without the use of pcntl_fork. Sure. Just start it and leave it running. I want to launch a daemon out of the /etc/rc.local when the system starts. Yep, I do that all the time. Anybody have any idea on how to do this? On an openSUSE system I would just use 'startproc', but elsewhere you could use setsid or nohup. I.e. create your CLI script with a hash-bang, then start it nohup script 21 1/dev/null /Per Again, that's not a daemon. If it is sufficient to run a background process then that's fine, but that doesn't make it a daemon (although it shares some things in common with a daemon). The background process still has a controlling terminal (even if input and output have been redirected), and a fully-implemented daemon will typically perform other tasks which make it a good system citizen, such as: becoming session leader, chroot'ing to / so that the filesystem it was started from can be unmounted if necessary, and so on. The difference may or may not be important, depending on the task at hand. However, if an admin thinks he's got a daemon on his hands he may wonder why things behave weird if what he really has is just something which fakes it with and nohup, since none of the important daemon housekeeping has been dealt with. Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] daemon without pcntl_fork
2009/8/18 Per Jessen p...@computer.org: Lars Torben Wilson wrote: Again, that's not a daemon. If it is sufficient to run a background process then that's fine, but that doesn't make it a daemon (although it shares some things in common with a daemon). The background process still has a controlling terminal (even if input and output have been redirected), and a fully-implemented daemon will typically perform other tasks which make it a good system citizen, such as: becoming session leader, chroot'ing to / so that the filesystem it was started from can be unmounted if necessary, and so on. Torben, you're really just splitting hairs - the OP didn't ask for the definition of daemon', he just wanted a script to run continually as if it was a daemon. Besides, I did also suggest using either setsid or openSUSEs startproc. Thank you for the lecture. Your opinion of my post on this is quite beside the point. If Jim needs a daemon, then he should probably use a daemon coded the best way possible. If not, then that's fine too. As you correctly pointed out, there are ways to fake it. I simply feel that Jim should be made aware of potential drawbacks. That's perhaps splitting hairs--it's also being thorough. Clients don't tend to appreciate being told that a lack of thoroughness arose from a fear of splitting hairs. Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] daemon without pcntl_fork
2009/8/17 Jim Lucas li...@cmsws.com: Does anybody know how to use PHP as a daemon without the use of pcntl_fork. http://php.net/pcntl_fork Hi Jim, AFAIK you can't. Read on. . . I don't want to have to have a person have a special/custom compilation of PHP just to run a simple daemon. My system: OpenBSD 4.5 w/PHP v5.2.8 I want to launch a daemon out of the /etc/rc.local when the system starts. My goal is to write a script that will be launched from /etc/rc.local when a system boots. I want it to be detached from any shell or ssh login that I launch it from also. Anybody have any idea on how to do this? I have played with system() and it does work. What you've done below is not create a daemon, but a background process. It's still attached to the shell you started it in (try killing the shell you started it from and see what happens). There are other differences too. IMHO the approach you've used here does have its uses, and I've used it (and still do) when it's appropriate, but when what you need is a daemon, then faking it with a background process just isn't enough. Compiling in pcntl isn't really that big of a deal--depending on exactly what you're trying to accomplish. Why is it a problem in your case? Perhaps there is another way around the issue which has a cleaner solution. For the cases I've run into, pcntl has worked admirably. test.php: ?php echo 'Starting'; system('/usr/local/bin/php test_cli.php /dev/null '); echo 'Done'; ? test_cli.php ?php for( $i=1; $i=10; $i++ ) { echo Echo {$i}\n; sleep(1); } echo 'Done'; ? The above, when called, launches test_cli.php and detaches it from the cli and returns to the system prompt Well, after writing all this out, I think I have answered by own question. If anybody else has a better suggestion, I am all ears. If you have a better way of doing it, please share. Also, a second piece to this would be a script to manage (start/stop/restart/etc...) the parent daemon. Something along the line of apachectl or similar. TIA! Update to the last email also. I found another device that does RS232 to ethernet: http://www.hw-group.com/products/portstore2/index_en.html Anybody work with one of these? Not me. But I've solved similar problems using ser2net (see http://sourceforge.net/projects/ser2net/ ), sometimes running it on a small embedded Linux device. Works great and I don't have to pay someone else to sell me a free solution. :) But again, it depends on your actual situation and what problem you're trying to solve. On the face of it the device you linked looks OK. (I'm afraid I missed your earlier post on the topic.) Again, thanks! Jim Lucas I'm not trying to shoot down any ideas you've had or anything, just wondering what's so bad about compiling pcntl in and hoping that maybe you can save a few bucks on the serial-to-network problem by making use of existing free software. Post more about what your situation is and who knows? Maybe a fakey-daemon using background processes and a proprietary serial-to-network device really is the best answer for you. Either way, good luck! Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] New PHP User with a simple question
2009/1/24 Christopher W cwei...@adelphia.net: At least I hope it is simple... I am trying to get an HTML menu link to set a variable's value. For example, when a user clicks the Home button on my page it would cause $page = home; or clicking the About Us button will set $page=about_us; etc. I think this should be fairly simple but being completely new to php I just cannot seem to get it right. Any help would be greatly appreciate. Thank you in advance. Hi there, A good way to increase your chance of getting a useful response is to post the smallest example you can which clearly illustrates the problem you're having. In this case, you say you're not able to get this to work, but we could waste quite a bit of time trying to guess what you've tried and what didn't work. In the simplest case, you could make your menu items look something like this: a href=target.html?page=homeHome/a and then use $page = $_GET['page'] in your script, but I wouldn't recommend it since now you have user data floating around in your script and it will later become a pain in the butt to sanitize for security. For a learning script it'll be fine though. Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] To check for existing user in database
2009/1/16 Shawn McKenzie nos...@mckenzies.net: Lars Torben Wilson wrote: 2009/1/15 tedd tedd.sperl...@gmail.com: At 9:46 AM -0800 1/15/09, Chris Carter wrote: Chris: That's not the way I would do it. After establishing a connection with the database, I would use the query: $query SELECT email FROM owners WHERE email = '$emailAddress' : $result = mysql_query($query) or die(mysql_error()); if(mysql_affected_rows()) { // then report a duplicate email/record. } else { // else insert a new record in the dB. } HTH's tedd You want to use mysql_num_rows() there instead of mysql_affected_rows(). (Just a typo in this case, I suspect, but for the benefit of the less experienced it's worth pointing out.) For the newer PHP users, mysql_num_rows() tells you the number of rows you found with a SELECT query, while mysql_affected_rows() tells you how many rows you affected with an INSERT, UPDATE, REPLACE INTO, or DELETE query. Regards, Torben mysql_num_rows() may make more sense, however mysql_affected_rows() will work the same with a select. The PHP mysql_affected_rows() calls the MySQL mysql_affected_rows(), which states: For SELECT statements, mysql_affected_rows() works like mysql_num_rows(). (My apologies for not following the thread for a week. . .) Yes, you are right, except that the restriction isn't with MySQL, it's within PHP. The problem is that if you leave out the optional resource argument it works like you describe, but if you include the argument, PHP barfs. It's good practice to use the one intended for the purpose at hand, even if the other will work in some (or even most) situations. I suppose this is a bug in PHP in that it should really behave the way that the MySQL API does to avoid surprises, but it does illustrate the point that using the intended function is easier in the long run: you know it's been tested against its intended usage and not necessarily against others. Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] distinguish between null variable and unset variable
2009/1/21 Daniel Brown danbr...@php.net: On Wed, Jan 21, 2009 at 20:27, Jack Bates ms...@freezone.co.uk wrote: How can I tell the difference between a variable whose value is null and a variable which is not set? Unfortunately, in PHP - like other languages - you can't. A variable is considered to be null if: * it has been assigned the constant NULL. * it has not been set to any value yet. * it has been unset(). Actually, you can, but it's not terribly pretty. Check for the variable name as a key in the array returned from get_defined_vars(): ?php $foo = 0; $bar = null; $variables = get_defined_vars(); // Check for $foo, $bar, and $baz: foreach (array('foo', 'bar', 'baz') as $var) { if (!array_key_exists($var, $variables)) { echo \$$var does not exist in the current scope.\n; continue; } if (is_null($$var)) { echo \$$var exists and is null in the current scope.\n; continue; } echo \$$var exists and is not null in the current scope.\n; } ? Again, not that pretty, and it only checks the local scope, but it can be done. Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] print a to z
2009/1/15 Leon du Plessis l...@dsgnit.com: I used that notation before, and it did not work 100%. Adapt as follows: for ($i = 'a'; $i = 'z'; $i++) if ($i == aa) break; else echo $i; It's weird, but true--the simple '=' breaks the loop. However, in the above example, you don't need the 'else'; the 'break' ensures that the 'echo $i'; will not execute. You can step around the the problem more elegantly: for ($i = 'a'; $i !== 'aa'; $i++) { echo $i; } Regards, Torben -Original Message- From: Paul M Foster [mailto:pa...@quillandmouse.com] Sent: 16 January 2009 07:55 AM To: php-general@lists.php.net Subject: Re: [PHP] print a to z On Thu, Jan 15, 2009 at 08:32:14PM -0800, paragasu wrote: i have this cute little problem. i want to print a to z for site navigation my first attempt work fine for($i = '65'; $i '91'; ++$i) echo chr($i); but someone point me a more interesting solutions for($i = 'a'; $i 'z'; ++$i) echo $i the only problem with the 2nd solutions is it only print up to Y without z. so how to print up to z with the 2nd solutions? because it turn out that you cant to something like for($i = 'a'; $i = 'z'; ++$i).. for ($i = 'a'; $i = 'z'; $i++) echo $i; Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] To check for existing user in database
2009/1/15 tedd tedd.sperl...@gmail.com: At 9:46 AM -0800 1/15/09, Chris Carter wrote: Chris: That's not the way I would do it. After establishing a connection with the database, I would use the query: $query SELECT email FROM owners WHERE email = '$emailAddress' : $result = mysql_query($query) or die(mysql_error()); if(mysql_affected_rows()) { // then report a duplicate email/record. } else { // else insert a new record in the dB. } HTH's tedd You want to use mysql_num_rows() there instead of mysql_affected_rows(). (Just a typo in this case, I suspect, but for the benefit of the less experienced it's worth pointing out.) For the newer PHP users, mysql_num_rows() tells you the number of rows you found with a SELECT query, while mysql_affected_rows() tells you how many rows you affected with an INSERT, UPDATE, REPLACE INTO, or DELETE query. Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String variable
2009/1/11 Ashley Sheridan a...@ashleysheridan.co.uk: On Sun, 2009-01-11 at 14:36 +, Ashley Sheridan wrote: On Sun, 2009-01-11 at 08:59 -0500, MikeP wrote: Hello, I am trying yo get THIS: where ref_id = '1234' from this. $where=where ref_id=.'$Reference[$x][ref_id]'; but i certainly have a quote problem. Any help? Thanks Mike It should look like this: $where=where ref_id='{$Reference[$x][ref_id]}'; Ash www.ashleysheridan.co.uk Sorry, it should look like this: $where=where ref_id='{$Reference[$x][ref_id]}'; I missed taking an extra quote mark out Closer, but still not quite there. For encapsulation in the string, it should look like: $where = where ref_is='{$Reference[$x]['ref_id']}'; Someone else mentioned casting to int first as well to sanitize, which is also a good idea. Torben Ash www.ashleysheridan.co.uk -- Torben Wilson tor...@2powerweb.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Re: How to count transfered kBytes in File-Download
2009/1/3 Ashley Sheridan a...@ashleysheridan.co.uk: On Sat, 2009-01-03 at 17:39 -0500, Eric Butera wrote: On Sat, Jan 3, 2009 at 5:19 PM, Michelle Konzack linux4miche...@tamay-dogan.net wrote: Am 2009-01-03 10:16:43, schrieb Eric Butera: On Sat, Jan 3, 2009 at 9:23 AM, Ashley Sheridan I don't think this is actually possible. I've never seen it happen before. It would need some sort of dedicated client-side software to recognise exactly how much has been downloaded and then request the rest of it. A browser doesn't yet have this capability I believe. wget and curl support resum broken download... $_SERVER['HTTP_RANGE'] ??? Hmmm, what is the value of this VAR? The BYTE where to start? If yes, how can I include this in my script? I mean, if I fread() I must skip this ammount of BYTES and then start sending, but how to skip it? Or I am wrong with fread()? Thanks, Greetings and nice Day/Evening Michelle Konzack Systemadministrator 24V Electronic Engineer Tamay Dogan Network Debian GNU/Linux Consultant -- Linux-User #280138 with the Linux Counter, http://counter.li.org/ # Debian GNU/Linux Consultant # http://www.tamay-dogan.net/ http://www.can4linux.org/ Michelle Konzack Apt. 917 ICQ #328449886 +49/177/935194750, rue de Soultz MSN LinuxMichi +33/6/61925193 67100 Strasbourg/France IRC #Debian (irc.icq.com) I don't know how it works, just know of it. Maybe I'm misunderstanding you, but are you looking for fseek? http://us3.php.net/manual/en/function.fseek.php Where does $_SERVER['HTTP_RANGE'] come from then, as I can't find anything about it online that actually says what it does, and when and what sets it. I can find lots of script listings that use it, but without knowing what it is, I don't know what to make of it. Ash www.ashleysheridan.co.uk It's an HTTP header, sent in the HTTP request as Range: byte-range. According to the CGI spec it's made available to CGI programs by the server in the HTTP_RANGE environment variable, so PHP picks it up and adds it to the $_SERVER array. Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] running python in php timeout
2008/12/29 brad bradcau...@gmail.com: Hi, I'm executing a python script from php that runs quite a long time (15+ minutes) and ends up timing out. Is there a way I can execute the python code and move on executing the remaining php code on the page? Thanks! Hi Brad, It's a little tough to say for sure since you didn't specify your OS or platform (always good info to include), but if you're on *nix then you'll need to tell the child process to run in the background and redirect the output from the child process to somewhere else (say, a log file). You also didn't say how you're executing the child process, but here's a common way to do it using backticks: `/path/to/executable $arg1 $arg2 /path/to/logfile.log 21 ` The ' /path/to/logfile.log' redirects standard output from the process to your log file. The '21' following that redirects the process's standard error to its standard output (which means that error messages will also be written to the log file), and the final ampersand puts the child process into the background. The same technique also works with exec() etc. Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] More microptimisation (Was Re: [PHP] Variable as an index)
2008/12/22 Nathan Nobbe quickshif...@gmail.com: On Mon, Dec 22, 2008 at 3:10 PM, Clancy clanc...@cybec.com.au wrote: On Mon, 22 Dec 2008 10:20:09 +1100, dmag...@gmail.com (Chris) wrote: I'd call this a micro-optimization. If changing this causes that much of a difference in your script, wow - you're way ahead of the rest of us. Schlossnagle (in Advanced PHP Programming) advises: $i = 0; while ($i $j) { ++$i; } rather than: $i = 0; while ($i $j) { ... $i++; } as the former apparently uses less memory references. However I find it very hard to believe that the difference would ever show up in the real world. nonsense, some college kid is going to put ++$i on a test to try an impress the professor when the semantics call for $i++ :D -nathan p.s. in case you couldnt tell; been there, done that. lol Well, in all fairness, it *is* faster--but you'll only notice the difference in extremely tight and long-running loops (try it ;) ). As long as you know why you're using it and what the side effects are, it would be fine. But as an optimization tool, I'd agree that it's pretty much pointless. It's good to remember the Rules of Optimization: #1) Don't. #2) (For experts only) Don't do it yet. Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] More microptimisation (Was Re: [PHP] Variable as an index)
2008/12/22 German Geek geek...@gmail.com: agree, ++$i wont save u nething, it just means that the variable is incremented after it is used: You meant . . .before it is used:, right? Torben $i = 0; while ($i 4) echo $i++; will output 0123 while $i = 0; while ($i 4) echo ++$i; will output 1234 Tim-Hinnerk Heuer http://www.ihostnz.com On Tue, Dec 23, 2008 at 7:25 PM, Nathan Nobbe quickshif...@gmail.comwrote: On Mon, Dec 22, 2008 at 3:10 PM, Clancy clanc...@cybec.com.au wrote: On Mon, 22 Dec 2008 10:20:09 +1100, dmag...@gmail.com (Chris) wrote: I'd call this a micro-optimization. If changing this causes that much of a difference in your script, wow - you're way ahead of the rest of us. Schlossnagle (in Advanced PHP Programming) advises: $i = 0; while ($i $j) { ++$i; } rather than: $i = 0; while ($i $j) { ... $i++; } as the former apparently uses less memory references. However I find it very hard to believe that the difference would ever show up in the real world. nonsense, some college kid is going to put ++$i on a test to try an impress the professor when the semantics call for $i++ :D -nathan p.s. in case you couldnt tell; been there, done that. lol -- Torben Wilson tor...@2powerweb.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular expressions (regex) question for parsing
2008/12/22 Jim Lucas li...@cmsws.com: Rene Fournier wrote: Hi, I'm looking for some ideas on the best way to parse blocks of text that is formatted such as: $sometext %\r\n-- good data $otherstring %\r\n-- good data $andyetmoretext %\r\n-- good data $finaltext -- bad data (missing ending) Each line should start with a $dollar sign, then some arbitrary text, ends with a percent sign, followed by carriage-return and line-feed. Sometimes though, the final line is not complete. In that case, I want to save those lines too. so that I end up with an array like: $result = array (matches = array (0 = $sometext %\r\n, 1 = $otherstring %\r\n, 2 = $andyetmoretext %\r\n ), non_matches = array (3 = $finaltext ) ); The key thing here is that the line numbers are preserved and the non-matched lines are saved... Any ideas, what's the best way to go about this? Preg_matc, preg_split or something incorporating explode? Rene Something along the line of this? pre?php $block_of_text = '$sometext %\r\n $otherstring %\r\n $andyetmoretext %\r\n $finaltext'; $lines = explode(\n, $block_of_text); $results = array(); foreach ( $lines AS $i = $line ) { if ( preg_match('|^\$.* %\\\r\\\n$|', $line ) ) { $results['matches'][$i] = $line; } else { $results['non_matches'][$i] = $line; } } print_r($results); ? I know I'm arguing against premature optimization in another thread at the moment, but using regexps for this is overkill from the get-go: if ($line[0] === '$' substr($line, -3) === %\r\n) { This is both faster and easier to read. Regexps are great for more complex stuff but something this simple doesn't demand their power (or overhead). Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable as an index
2008/12/21 German Geek geek...@gmail.com: Yes, i agree with this. Even if it takes a few nano seconds more to write out more understandable code, it's worth doing it because code management is more important than sqeezing out the last nano second. And then also an $var = Hello; echo $val World; has less characters than and is more readable than $var = Hello; echo $var . World; So it would take maybe a few nano seconds less to read it from the hard drive. And we all know that disk I/O is more expensive than pushing around variables in main memory in terms of time. And RAM is soo cheap these days. Tim-Hinnerk Heuer http://www.ihostnz.com Agreed. Although I tend to use ' instead of unless I need interpolation, if I feel it's really going to make that much of a difference then I start looking at rewriting that section in C or refactoring. String interpolation shouldn't be a bottleneck. Getting back to the original question though, the correct way to express a multidimensional array access inside a string is to use curly braces, and include quotes around any string index names: echo An array: {$arr[$foo]['bar']}\n; Torben On Mon, Dec 22, 2008 at 12:50 PM, Anthony Gentile asgent...@gmail.comwrote: True, it might mean the very slightest in milliseconds...depending on what you're doing/hardware. However, no harm in understanding the difference/how it works. Many will code echo Hello World and echo 'Hello World'; and never know the difference, I just happen to think being aware of the details will help for the long term programmer. Since, I brought it up, I'll go ahead and give another example. Ternaries that make a lot of people feel awesome because a lot is being accomplished in one line are also more opcodes than their if-else statement equivalents...and often times can be more confusing to future maintainers of the code. Anthony Gentile On Sun, Dec 21, 2008 at 6:20 PM, Chris dmag...@gmail.com wrote: Anthony Gentile wrote: for e.g. $var = 'world'; echo hello $var; vs echo 'hello '.$var; The first uses twice as many opcodes as compared to the second. The first is init a string and adding to it the first part(string) and then the second part (var); once completed it can echo it out. The second is simply two opcodes, a concatenate and an echo. Interpolation. I'd call this a micro-optimization. If changing this causes that much of a difference in your script, wow - you're way ahead of the rest of us. http://blog.libssh2.org/index.php?/archives/28-How-long-is-a-piece-of-string.html http://www.phpbench.com/ -- Postgresql php tutorials http://www.designmagick.com/ -- Torben Wilson tor...@2powerweb.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] gethostbyaddr and IPv6
2008/11/21 Glen C [EMAIL PROTECTED]: Hello, Does gethostbyaddr actually work for anyone while looking up an IPv6 address? I can't seem to get it to work. For example: echo gethostbyaddr ( '2001:470:0:64::2' ); should return ipv6.he.net but instead I get the following error: [21-Nov-2008 22:43:37] PHP Warning: gethostbyaddr() [a href='function.gethostbyaddr'function.gethostbyaddr/a]: Address is not in a.b.c.d form in C:\www\tests\saved\host.php on line 7 Google has not been my friend in this matter... Any insight? Thanks, Glen Hi Glen, Works for me. IPv6 support was added in 2001. You didn't say what version of PHP you are having this problem with, so it's hard to say why yours doesn't have support for it. Perhaps it was configured with --disable-ipv6 for some reason, or compiled on a system without the necessary libraries installed (which would be somewhat surprising). Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] gethostbyaddr and IPv6
2008/11/21 Glen Carreras [EMAIL PROTECTED]: On 11/22/2008 12:10 AM, Lars Torben Wilson wrote: Hi Glen, Works for me. IPv6 support was added in 2001. You didn't say what version of PHP you are having this problem with, so it's hard to say why yours doesn't have support for it. Perhaps it was configured with --disable-ipv6 for some reason, or compiled on a system without the necessary libraries installed (which would be somewhat surprising). Torben Thanks for the confirmation that it works Torben, This is version 5.2 (Windows binaries) and according to phpinfo ipv6 is enabled. Hmmm well, at least I now know for sure that it works for someone else and I can start exploring other avenues. I'm starting to think this is another problem resulting from Microsofts poor implementation of IPv6 on XP. Glen Hi Glen, I suspect that you may be correct--I generally don't run Windows (certainly not as a server) so I can't be sure; someone with more knowledge of Windows internals will have to field that one for you. With any luck you might find something in the user notes which leads you to a way to solve your problem using some other function or idea. Just for future reference, if you're having problems it will help people to answer your questions if you specify your PHP version and OS etc (where 'etc' means 'and all other relevant information, which of course won't be obvious--hehe) when writing the original question. I ain't tryin' to be some kind of netiquette freak here--just trying to help out. :) Anyway, good luck on your quest. Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Invalid Arguements
2008/11/19 Robert Cummings [EMAIL PROTECTED]: On Wed, 2008-11-19 at 19:49 +, Ashley Sheridan wrote: On Wed, 2008-11-19 at 08:31 -0600, Terion Miller wrote: I am still getting the Invalid arguement error on this implode: if (isset($_POST['BannerSize'])){$BannerSize = implode(',',$_POST['BannerSize']);} else {$BannerSize = ;} I have moved the ',', from the beginning to the end of the statement and nothing works is there any other way to do this, basically there is a form and the people entering work orders can select different sized banners they need, which goes into the db as text so...argh... As mentioned quite a few times before, you cannot change the order of the arguments, it will not work! There is no indicator in the PHP Manual page for this function either that says you can switch the orders, so I'm not sure why you think you can. In PHP 5.2.6 and in PHP 4.4.9 I get the same output for the following: ?php $foo = array( 1, 2 ); echo implode( $foo, ',' ).\n; echo implode( ',', $foo ).\n; ? I believe, that a long time ago it was added as a feature so that PHP would detect inverted parameter order on this particular function and output appropriately. It is probably undocumented so as to encourage a single documented order. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP It was added a long time ago, yes, and it is indeed documented (as already noted in this thread). I'm not sure which copy of the manual Ash is reading from, but the one I'm looking at documents this behaviour. And it's right there in the PHP source code (and easily testable, as you have shown). Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] in_array breaks down for 0 as value
2008/11/20 Stut [EMAIL PROTECTED]: On 20 Nov 2008, at 06:55, Yashesh Bhatia wrote: I wanted to use in_array to verify the results of a form submission for a checkbox and found an interesting behaviour. $ php -v PHP 5.2.5 (cli) (built: Jan 12 2008 14:54:37) $ $ cat in_array2.php ?php $node_review_types = array( 'page' = 'page', 'story' = 'story', 'nodereview' = 'abc', ); if (in_array('page', $node_review_types)) { print page found in node_review_types\n; } if (in_array('nodereview', $node_review_types)) { print nodereview found in node_review_types\n; } ? $ php in_array2.php page found in node_review_types $ This works fine. but if i change the value of the key 'nodereview' to 0 it breaks down. $ diff in_array2.php in_array3.php 6c6 'nodereview' = 'abc', --- 'nodereview' = 0, $ $ php in_array3.php page found in node_review_types nodereview found in node_review_types $ Any reason why in_array is returning TRUE when one has a 0 value on the array ? That's weird, 5.2.6 does the same thing. There's actually a comment about this on the in_array manual page from james dot ellis at gmail dot com... quote Be aware of oddities when dealing with 0 (zero) values in an array... This script: ?php $array = array('testing',0,'name'); var_dump($array); //this will return true var_dump(in_array('foo', $array)); //this will return false var_dump(in_array('foo', $array, TRUE)); ? It seems in non strict mode, the 0 value in the array is evaluating to boolean FALSE and in_array returns TRUE. Use strict mode to work around this peculiarity. This only seems to occur when there is an integer 0 in the array. A string '0' will return FALSE for the first test above (at least in 5.2.6). /quote So use strict mode and this problem will go away. Oh, and please read the manual before asking a question in future. -Stut I wouldn't consider it weird; it's just how PHP handles loose type comparisons. I would certainly agree that it's not terribly obvious why it happens, though. :) That said, it's consistent with PHP behaviour. James Ellis almost got it right in his note. As I already noted, it's not because of a conversion to boolean FALSE, but a conversion to integer 0. You can test this by substituting FALSE for the 0 in the array in the example and trying it. Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] in_array breaks down for 0 as value
2008/11/19 Yashesh Bhatia [EMAIL PROTECTED]: Hi. I wanted to use in_array to verify the results of a form submission for a checkbox and found an interesting behaviour. $ php -v PHP 5.2.5 (cli) (built: Jan 12 2008 14:54:37) $ $ cat in_array2.php ?php $node_review_types = array( 'page' = 'page', 'story' = 'story', 'nodereview' = 'abc', ); if (in_array('page', $node_review_types)) { print page found in node_review_types\n; } if (in_array('nodereview', $node_review_types)) { print nodereview found in node_review_types\n; } ? $ php in_array2.php page found in node_review_types $ This works fine. but if i change the value of the key 'nodereview' to 0 it breaks down. $ diff in_array2.php in_array3.php 6c6 'nodereview' = 'abc', --- 'nodereview' = 0, $ $ php in_array3.php page found in node_review_types nodereview found in node_review_types $ Any reason why in_array is returning TRUE when one has a 0 value on the array ? Thanks. Hi Yasheed, It looks like you've found the reason for the existence of the optional third argument to in_array(): 'strict'. In your second example (in_array3.php), what happens is that the value of $node_review_types['nodereview'] is 0 (an integer), so it is compared against the integer value of the first argument to in_array(), which is also 0 (in PHP, the integer value of a string with no leading numerals is 0). In other words, in_array() first looks at the first element of $node_review_types and finds that it is a string, so it compares that value as a string against the string value of its first argument ('nodereview'). Same goes for the second element of $node_review_types. However, when it comes time to check the third element, in_array() sees that it is an integer (0) and thus compares it against the integer value of 'nodereview' (also 0), and returns true. Make any sense? The problem goes away if you give a true value as the third argument to in_array(): this tells it to check the elements of the given array for type as well as value--i.e., it tells in_array() to not automatically cast the value being searched for to the type of the array element being checked. Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count the Number of Elements Using Explode
2008/10/31 Stut [EMAIL PROTECTED]: On 31 Oct 2008, at 17:32, Maciek Sokolewicz wrote: Kyle Terry wrote: -- Forwarded message -- From: Kyle Terry [EMAIL PROTECTED] Date: Fri, Oct 31, 2008 at 9:31 AM Subject: Re: [PHP] Count the Number of Elements Using Explode To: Alice Wei [EMAIL PROTECTED] I would use http://us2.php.net/manual/en/function.array-count-values.php On Fri, Oct 31, 2008 at 9:29 AM, Alice Wei [EMAIL PROTECTED] wrote: Hi, I have a code snippet here as follows: $message=1|2|3|4|5; $stringChunks = explode(|, $message); Is it possible to find out the number of elements in this string? It seems that I could do things like print_r and find out what is the last element of $stringChunks is, but is there a way where I can use code from the two lines and have it print out 5 as the number of elements that contains after the splitting? Or, am I on the wrong direction here? Thanks in advance. Alice First of all, don't top post, please. Secondly, that won't do what the OP asked for. array_count_values returns an array which tells you how often each VALUE was found in that array. so: array_count_values(array(1,2,3,4,5)) will return: array(1=1,2=1,3=1,4=1,5=1). While what the OP wanted was: some_function(array(1,2,3,4,5)) to return 5 (as in the amount of values, not how often each value was found in the array). count() would do it directly, and the other suggestions people gave do it indirectly, assuming that the values between '|' are never 1 char wide. I think you'll find Kyle was suggesting that the OP use that function to count the |'s in the string. Add 1 to that and you have the number of elements explode will produce. More efficient if you're simply exploding it to count the elements, but count would be better if you need to explode them too. -Stut For the case where you want to explode a string and afterwards count the number of elements you wind up with, Maciek is right: count() is the correct function to use. array_count_values() will not work on the original string and after exploding will have no useful effect on the resulting string as far as counting the number of separators goes. If you don't actually need to explode the string but just want to count the separators, you could use some weird logic to get array_count_values() to count the number of times '|' appeared in the original string--but it would be pointless. count_chars() would be a much better choice for what you are suggesting. Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dynamically creating multi-array field
2008/10/26 Martin Zvarík [EMAIL PROTECTED]: PHP Version 5.2.4 ? $node = '[5][1][]'; ${'tpl'.$node} = 'some text'; print_r($tpl); // null ? I really don't like to use the EVAL function, but do I have choice?? This sucks. Hi there, While this question can spur some neat solutions, it raises a red flag in that if you need to do this, you probably need to rethink things a bit. In cases like this it is easier for people to help if you describe the actual problem you are trying to solve, not how you think it needs to be solved. It could be that you don't really need weird (but beautiful, like Jim's idea) solutions. If you explain why you believe that you need to do this in the first place, maybe someone can suggest something else which doesn't require a weird solution (however beautiful). Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dynamically creating multi-array field
2008/10/27 Martin Zvarík [EMAIL PROTECTED]: Hi, I am aware of this, but explaining my problem in this case would take me an hour --- and eventually would lead to a) misunderstanding, b) weird solution, c) no solution... Forgive me if I misunderstand, but it seems like you are willing to trade off an hour at the beginning of the project at the expense of perhaps many hours of pain later on. Has this thread not already taken more than an hour? I find that often if I have a weird question, just taking the time to formulate and write a good descriptive post to explain the problem helps me understand why I'm going at it the wrong way to start with. I remember years ago being faced with the same problem you now have. It turned out that the most elegant solution was to change the design so that I didn't need to solve the problem at all. Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Disk serial number
Rosen wrote: I would like to create it as module for PHP like function - like gethdserial() - and function to retrieve me serial number of HDD. I know how to retrieve serial number in C, Delphi. I assume you want to do it the hard way to learn about programming modules...? As others have said, try the PECL site (http://pecl.php.net). Look on the 'Documentation' page. Click on the 'Developing custom PHP extendsions'. Check out the other links on the page as well; there appear to be quite a few of them. Also, Google will help. So will the mailing list archives, and also, just read through some of the existing modules. Torben Lars Torben Wilson [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Rosen wrote: I can write it to another language ( like C, Delphi ) but I don't know how to integrate this with PHP - i.e. to create it as module for PHP. I would suggest going the simple route for now, then if you need it (for performance or whatever) later on, write it up as a module then. Write a simple little program in whatever language you like which can fetch the id and print it to standard output. Compile it and test it. Then in your PHP script, just call that program (using exec(), system(), backticks, whatever works best for your situation) and read its output. Later on, decide whether you need to write a whole module for this task. Seems like it would be overkill to me. Cheers, Torben [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Disk serial number
Rosen wrote: I can write it to another language ( like C, Delphi ) but I don't know how to integrate this with PHP - i.e. to create it as module for PHP. I would suggest going the simple route for now, then if you need it (for performance or whatever) later on, write it up as a module then. Write a simple little program in whatever language you like which can fetch the id and print it to standard output. Compile it and test it. Then in your PHP script, just call that program (using exec(), system(), backticks, whatever works best for your situation) and read its output. Later on, decide whether you need to write a whole module for this task. Seems like it would be overkill to me. Cheers, Torben [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] exec/system question..
Justin Patrin wrote: On Wed, 21 Jul 2004 13:55:37 -0500, Michael Sims [EMAIL PROTECTED] wrote: Michael Sims wrote: Justin Patrin wrote: On Wed, 21 Jul 2004 10:09:52 -0700, bruce [EMAIL PROTECTED] wrote: 2) i could run the perl script, and have it somehow run in the background this would ba good, if there's a way to essentially [...] AFAIK there's no way to do this. When the request ends (user hits stop, exit or die called) the process is ended. This includes children. There are ways around that, though, at least if you're running unix: exec('bash -c exec nohup setsid your_command /dev/null 21 '); Sorry to followup to my own post, but I just did some quick testing and apparently none of the above (nohup, setsid) is really necessary. As long as the output of the command is redirected somewhere and the is used to start it in the background it will continue to run even if the process that launched it exits or is killed. I tested this with the following (named 'test.php'): --- #!/usr/local/bin/php ? if (isset($argv[1])) { exec('./test.php /dev/null '); } sleep(10); exec('wall testing - ignore '.getmypid()); ? --- I opened two SSH sessions, ran the above script in one (using './test.php 1') then immediately exited the SSH session. The PHP processes (both of them) continued to execute and I saw the wall output from both scripts in my other SSH session. So apparently the nohup setsid stuff is overkill... Did you try it from the web? Just to be devil's advocate and be sure that, say, clicking Stop doesn't stop the background process. Also, does *killing* the original script kill the child? It's a well-understood technique; I have used it quite a bit--mostly in web-based scripts. If you like, you can even redirect your output to a file instead of /dev/null, and put a refresh on the calling page which checks that file, providing a progress update on each reload. Hope this helps, Torben [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Putting $_POST into string to send to ASP
Jeff Oien wrote: Dumb question, sorry if it's a repeat. I will use PHP for a form with error checking. When there are no errors I need to send all the variables thru something like this: $URL = https://example.com/script.asp?First=JimLast=Smith;; urlencode($URL); header(Location: $URL\n); How do I gather up all the variables in $_POST and attach them as a string after the question mark? Thanks. Jeff Try the http_build_query() function. If you don't have PHP 5, look in the user notes--someone appears to have written one for PHP 4 as well (the user note 21-Jun-2004 from 'brooklynphil'). I haven't tested either one. http://www.php.net/manual/en/function.http-build-query.php Using this, you could just do something like: $query_string = http_build_query($_POST); Hope this helps, Torben [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Putting $_POST into string to send to ASP
Vail, Warren wrote: How about (probably one of fifty solutions; Foreach($_POST as $k = $v) $vals[] = $k.=.$v; $strvals = urlencode(implode(,$vals)); Header(Location: https://example.com/script.asp?.$strvals); One thing to think about, URL's are limited in length, and one reason for using method=post is that they won't fit in a URL, for this you'll need to make sure they fit. Warren Vail You could do that, but for one thing, it doesn't handle arrays. The code snippet in the user notes does. -- Torben Wilson [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Putting $_POST into string to send to ASP
Jeff Oien wrote: Thanks for the helpful examples. One other question. Is there an advantage to sending the URL via a header as opposed to doing http_post like this? http://shiflett.org/hacks/php/http_post Jeff As mentioned a couple of times, size is one. But you still need to url-encode the data if you're going to send it via post. ?php $data = array('item1' = 'value1', 'item2' = 'value2'); $query_string = http_build_query($data); // Now, you can send the data either via post: $response = http_post('www.example.com', '/form.php', $data); // ...or via get: header('http://www.example.com?form.php?' . $data); ? The first lets your script grab the output of the form to which you're submitting (it's in $response after the http_post() call); the second actually loads and displays the target form. Another option is cURL, which is designed for exactly this sort of thing: http://www.php.net/curl ...but it may or may not be overkill for what you need. However, cURL pretty much rules the data posting/fetching game as far as configurability etc. Cheers, Torben [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: fread error
Don wrote: Hi, Using a a flat text file based calendar script. Started getting this error after upgrading PHP: Warning: fread(): Length parameter must be greater than 0 Function it is occurring in is: function read_str($fp) { $strlen = $this-bin2dec(fread($fp,4),4); return fread($fp, $strlen); } Any ideas? Thanks, Don It's hard to say without knowing what you're trying to do, but it looks like you're first reading a length value from the file, then reading that number of bytes? In which case if the first fread() fails or returns 0, and assuming $this-bin2dec() is doing its job correctly, you might want to skip trying the second fread(): function read_str($fp) { if ($strlen = $this-bin2dec(fread($fp, 4), 4)) { return fread($fp, $strlen); } } ...this will return NULL if there is nothing to read (i.e. the first fread() returns 0 or false). Essentially, the error is occurring because fread() doesn't want a 0 in the length argument, but there is no check in the code to ensure that this doesn't happen. The above is just one way to possibly get around it. Hope this helps, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Worried about PECL
Peter Clarke wrote: Currently the online manual for php is great. My concern is that the documentation for PECL extensions is almost non-existent. Since some php extensions are being moved/replaced by PECL extensions are we going to get non-existent documentation? Hi there, You might want to get onto one of the PECL lists if you intend to use it. http://pecl.php.net/support.php Someone there would be better able to help you. However, the short answer to your question is: The docs will be written when somebody decides to sit down and write them. The glib answer is just to give you the checkout information for the docs source tree. ;) A huge percentage of the current manual was written by people who realized there was no documentation, and decided to remedy the problem. In fact, it's how I learned about PHP's internals, and about a great deal of what makes it tick on the inside. Reading the source and translating it into documentation is a wonderful learning tool. For now, you're probably just safest sticking with mime_content_type(). If you're worried about it becoming obsolete (read: being moved fully to PECL from one version to the next), then wrap mime_content_type() in a function or class, and stick it in its own include file. When you have the information you need to move on to the PECL replacement, just write another copy of that same function, but have it access Fileinfo instead of mime_content_type(). Assuming that you've written both versions of the function to take the same (or similar) argument lists and return the same thing, then all you need to do to change from one to the other is replace the old include file with the new one. Hope this helps, Torben Wilson [EMAIL PROTECTED] For example: www.php.net/mime-magic This extension has been deprecated as the PECL extension fileinfo provides the same functionality (and more) in a much cleaner way. http://pecl.php.net/package/Fileinfo provides no documentation so what these extra functions are, I have no idea. Worse, I now have no idea how to do mime_content_type(). www.php.net/mcal Note: This extension has been removed as of PHP 5 and moved to the PECL repository. There is no mention of mcal on the pecl website. I appreciate that PECL will more relevant to PHP5, but PHP5 is close is the documentation close too? -Peter -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] post without form
Josh Close wrote: So basically there is no easy way around this. What I'm trying to do is have a page return to a page that was a couple pages back with the same get info. On the second page I can do $return_url = $_SERVER['HTTP_REFERER']; to get the previous url. But then I need to pass it on to the next page, then that page will return to the $return_url. I think passing via $_SESSION vars or cookies would be easier then doing actual socket posts. If there is an easier way than session or cookies to do this, I'd like to know. -Josh It's super easy, actually. There's been a wee bit of code floating around the mailing list for 5 or so years for this: function PostToHost($host, $path, $data_to_send) { $fp = fsockopen($host,80); fputs($fp, POST $path HTTP/1.1\n); fputs($fp, Host: $host\n); fputs($fp, Content-type: application/x-www-form-urlencoded\n); fputs($fp, Content-length: .strlen($data_to_send).\n); fputs($fp, Connection: close\n\n); fputs($fp, $data_to_send); while(!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } Just modify to suit and you're good to go. Note: you need to URL-encode the data you send into a string before passing it to the above function. Hope this helps, Torben -- Torben Wilson [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] post without form
Marek Kilimajer wrote: Lars Torben Wilson wrote: Josh Close wrote: So basically there is no easy way around this. What I'm trying to do is have a page return to a page that was a couple pages back with the same get info. On the second page I can do $return_url = $_SERVER['HTTP_REFERER']; to get the previous url. But then I need to pass it on to the next page, then that page will return to the $return_url. I think passing via $_SESSION vars or cookies would be easier then doing actual socket posts. Use session var if you are already using sessions, else use cookie Sessions are one way to deal with it, and would make the thing much easier than setting your own cookies and hoping the user has cookies' enabled (never a safe bet)--at least, assuming your PHP is configured correctly. However, unless you wanted to send all the form data in the cookie, you then need a way to store the data on the server side, probably in the session manager. Not hard, but not an obvious win over just posting the data where you wish. In this situation, I would probably combine the two techniques and just store the $return_url in a session var and then use the postToHost() function to do the final post back to that page. If there is an easier way than session or cookies to do this, I'd like to know. -Josh It's super easy, actually. There's been a wee bit of code floating around the mailing list for 5 or so years for this: but try to make the code working in the browser ;) Not sure what you mean here. The browser is irrelevant with the posting code. Using sessions means more interaction with the browser, not less. The less you need to depend on the browser, the less you'll have to debug. Granted, with the proper setup this is not so much of an issue with sessions, but just posting the data saves a bit of server-side work. Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Client IP
Rosen wrote: IP adress not send ?!? And how server communicate with client ? [snip] The httpd server might know the remote IP address, but that doesn't mean that it has to tell PHP about it. The SAPI module may or may not set the value, for instance. Even if you could rely on the IP address, in many cases it will not do quite what you want. For instance, if you try to organize users by IP address, you'll find that many users can appear to have the same IP address, such as when they're behind a firewall or using a workstation on an internal LAN--they may all appear to be coming from the same address. Hope this helps clear it up, Torben $_SERVER[REMOTE_ADDR] Either method will work. You just have to realize that sometimes the IP address is not sent. There is no reliable way to get the clients IP address, so do not depend on it. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- Torben Wilson [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Client IP
Rosen wrote: Ok, I don't understand why IP adress will bi invisible for $_SERVER variable. It should be there, but mostly because the CGI 1.1 spec requires that it be provided to the script. There is no physical requirement for it to be there. Reasons for it not being present could include: o Incomplete SAPI code; o A bug in the httpd or SAPI module, o etc... Even if it is there, it's entirely possible that it's just the IP address of a proxy--or even some other IP address entirely; it's not hard to spoof. Of course, all of this only applies when running as a CGI or module for handling web requests. No $_SERVER['REMOTE_ADDR'] will be set when running on the command line. Torben John W. Holmes [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Rosen wrote: Can I get just adress of the IP, with which the server communicates ? If you don't see the IP address somewhere in the $_SERVER variable, then NO. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Bug ?
Siddharth Hegde wrote: While we are on this topic, I have noticed that for only some keys, the following does not work $arr[KEY_NAME] but when I change this to $arr['KEY_NAME'] it works. I seriosuly doubt that KEY_NAME is a restricted keyword as dreamweawer highlights these in different colors and this happens very rarely. In any case I will be working on PHP5 so i guess it will not happen again This is explained in the manual section on arrays: http://www.php.net/manual/en/language.types.array.php#language.types.array.donts Sorry if that link wraps. Cheers, -- Torben Wilson [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with session on first page loaded
Jordi Canals wrote: Angelo, thanks for your comments. session_name must go before session_start. I think register_globals has nothing to do with session cookies. I always work with register_globals = off as recommended. About the cookie params (In PHP.INI) I checked them on the two platforms with phpinfo() and are exactly the same. I'm relly lost with this issue. It is not a browser problem, because browsers are accepting (and saving) the cookies. I tested it with Firefox, MSIE and Mozilla, and always have the same issue. Why the first page loaded, and only the first one, passes the session ID on the URL? I think perhaps could be something related with the system trying to read the cookie on the same page that first created it. But don't find a way to solve it. Thanks for your time, Jordi. Was your binary compiled with --enable-trans-sid? If so, I imagine the explanation would be something along the lines that because the session manager doesn't know whether you have cookies enabled until it gets a cookie back, it uses trans_sid. On the second page view, it gets a cookie, and starts using cookies instead. No research went into this; it's just a guess. ;) Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: I'm very curious about the object-orientated thingies in PHP 5.....
Scott Fletcher wrote: Hey everyone, I'm very curious about the object-orientated thingies in PHP 5. Anyone know of a sample scripts I can read it on? And how does it work since the browser-webserver is one sided in communication or one way, not both way? Scott F. Zend.com is absolutely drowning in information about PHP 5, and is probably your best bet to start. The client-server nature of running PHP on the web and object orientation are totally unrelated, so you don't have to worry about that. Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: regex problem
Josh Close wrote: I'm trying to get a simple regex to work. Here is the test script I have. #!/usr/bin/php -q ? $string = hello\nworld\n; $string = preg_replace(/[^\r]\n/i,\r\n,$string); First, the short version. You can fix this by using backreferences: $string = preg_replace(/([^\r])\n/i, \\1\r\n, $string); Now, the reason: preg_replace() replaces everything which matched, so both the \n and the character before it will be replaced (as they both had to match to make the pattern match). Luckily, preg_replace() stores a list of matches, which you can use either later in the same pattern or in the replace string. This is called a 'backreference'. You can tell preg_replace() which part(s) of the pattern you want to store in this fashion by enclosing those parts in parentheses. In your case, you want to store the character before the \n which matched, so you would enclose it in parentheses like so: /([^\r])\n/i. Thereafter you can refer to that portion of the pattern match with the sequence \1. If you add another set of parens, you would refer to it with \2...and so on. You can even nest pattern matches like this, in which case they are counted by the opening paren. So the replacement string would then become \\1\r\n. (You need the extra \ in front of \1 to prevent PHP's string interpolation parsing the \1 before it gets passed to preg_replace()). A lot more information is available from the manual page on preg_replace(): http://www.php.net/preg_replace There is also an extensive pages on pattern syntax: http://www.php.net/manual/en/pcre.pattern.syntax.php Hope this helps, Torben $string = addcslashes($string, \r\n); print $string; ? This outputs hell\r\nworl\r\n so it's removing the char before the \n also. I just want it to replace a lone \n with \r\n -Josh -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: TAB Syntax
Harlequin wrote: Cheers Lars. So, for example, if I wanted to display some plain text tabbed I'd use: echo prestring1\tstring2\tstring3/pre; There's just one problem though - it formats the text differently to the rest of the page (I'm using CSS to control this). Any thoughts...? Try adding 'white-space: pre;' to the CSS for that bit: div style=white-space: pre; ?php echo This\tis\n\ta test.; ? /div See if adding that helps. Cheers, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: test if $int is integer
Vlad Georgescu wrote: how can test if var $int is integer ? In the manual: http://www.php.net/is_int Another one which might be helpful: http://www.php.net/is_numeric Hope this helps, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: test if $int is integer
Matthew Sims wrote: I recently purchased George Schlossnagle's Advanced PHP Programming and on page 85 in the Error Handling chapter, he made a reference about the is_int function. In the above function example he had: if (!preg_match('/^\d+$/',$n) || $n 0) { In which he mentions: It might be strange to choose to evaluate whether $n is an integer by using a regular expression instead of the is_int function. The is_int function, however, does not do what you want. It only evaluates whether $n has been typed as a string or as an integer, not whether the value of $n is an integer. Can anyone comment on this? Sure. He's right, but this shouldn't be a surprise, since it's documented as such: Note: To test if a variable is a number or a numeric string (such as form input, which is always a string), you must use is_numeric(). (From http://www.php.net/is_int) In my opinion, using the regex engine for this is overkill. Another way is to do something like this (from the old days before is_numeric()): if ((string) (int) $int == $int) { echo '$int' is an integer.\n; } else { echo '$int' is not an integer.\n; } Now, this won't work for hex integers inside strings, but then, neither will the above regex. Also, for some reason the test you posted fails for negative values, which the simpler typecast test does not do. (There is a user note on the is_numeric() manual page with a function using the casting method for a wider range of numeric values, if you want it.) Mostly, though, is_numeric() will work just fine, but doesn't discriminate against floats etc (which both snippets above do). Torben --Matthew Sims --http://killermookie.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: TAB Syntax
Harlequin wrote: I know I'm probably going to get flamed for this but it is only a development site but I am having some trouble getting the syntax right for using the tab when echoing information. My current command is: print_r(Host: $hostbrUser: $userbrPassword: $password); I've tried: print_r(Host: \t$hostbrUser: $userbrPassword: $password); and god knows what else with the brackets etc. Any ideas...? It's expected behaviour, when outputting to a web browser. Browsers fold multiple whitespaces together. The two examples above should display identically. Try wrapping the above outputs in pre tags, though, to see the difference: ?php $host = 'localhost'; $user = 'torben'; $password = 'none'; echo bThe next two examples should display identically/bbr; echo Host: $hostbrUser: $userbrPassword: $passwordbr; echo Host: \t$hostbrUser: $userbrPassword: $passwordbrbr; echo Host: $hostbrUser: $userbrPassword: $passwordbr; echo Host: \t$hostbrUser:\n\n\t\n$userbrPassword: $passwordbr; echo hrbThe next two examples should display differently/bbr; echo preHost: $hostbrUser: $userbrPassword: $passwordbr/pre; echo preHost: \t$hostbrUser: $userbrPassword: $passwordbr/pre; echo preHost: $hostbrUser: $userbrPassword: $passwordbr/pre; echo preHost: \t$hostbrUser:\n\n\t\n$userbrPassword: $passwordbr/pre; ? Hope this helps, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Question about executing PHP script
Charlie Don wrote: Hello, I need to have some scripts that do database maintanance on my cron tab. However, some might take more time to execute that the maxtime set on php.ini. These are now web scripts but scripts that I execute on my command prompt or cron tab. I wonder if there is any way to have on the first line of the script that calls the php engine an option that does not end the script if it exceeds the maximum executin time. Thanks, C. Searching on Google for something like 'php max execution time' should land you on the correct manual page fairly quickly. To wit: http://www.php.net/set_time_limit Hope this helps, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Sort a text string by last word before separator
Andre Dubuc wrote: Given a text string: $OK = Joe Blow, William Howard Anser, Hannie Jansen, etc, etc,; [snip] How would I get this 'before_last' function to iterate through the initial string, so I could build a sorted list with both first and last names, sorted by last name? I can't seem to get a proper 'foreach' statement to work, nor a 'while' statement. There are few different ways. Here's one: --- function splitSortNames($namePartSeparator, $nameSeparator, $nameString) { preg_match_all('/(\w+)((\s(\w+)\s)*(\s?(\w+)))*/', $nameString, $tmp_names, PREG_SET_ORDER); $names = array(); foreach ($tmp_names as $i = $name) { $tmp = array(); if (!empty($name[6])) $tmp[1] = $name[6]; if (!empty($name[1])) $tmp[2] = $name[1]; if (!empty($name[4])) { $tmp[2] .= ' ' . $name[4]; } $names[$name[0]] = join(', ', $tmp); } asort($names); $names = array_keys($names); return $names; } $names = splitSortNames(' ', ', ', $OK); print_r($names); --- To check out a few other ideas along with a short (likely inaccurate) speed test, check out http://www.thebuttlesschaps.com/sortByLast.html (there is a 'View Source' link at the bottom of the page). This code returns the names in the format in which they are given. You can speed it up a bit by having it return the names in 'lastname, firstname' format. For this, change $names[$name[0]] = join(', ', $tmp); to $names[$i] = join(', ', $tmp); and remove the lines: asort($names); $names = array_keys($names); I'm really confused. I've read almost every entry on arrays/strings and searched code snippets. Almost all focus on one element arrays such apple, orange, peach rather than 2 or more elements such as fancy cars, big trucks, fast dangerous motorcycles, Is it even possible to accomplish this type sort on a string? Any advice, pointers, or help will be greatly appreciated, Tia, Andre Hopefully the code above will give you some aid--and you can probably improve on that regexp in preg_match_all(). The other 2 ways on the site have totally different methods, and different strengths and weaknesses. Maybe you can turn one of them into something useful to you. Hope this helps, Torben -- Torben Wilson [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Sort a text string by last word before separator
Lars Torben Wilson wrote: Sorry about following up to myself, but I was really really hungry when I wrote the first one: [snip] This code returns the names in the format in which they are given. You can speed it up a bit by having it return the names in 'lastname, firstname' format. For this, change $names[$name[0]] = join(', ', $tmp); to $names[$i] = join(', ', $tmp); and remove the lines: asort($names); Don't remove the above line; just change it to: sort($names); $names = array_keys($names); Cheers, Torben -- Torben Wilson [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] List Administrator
On Wed, 2003-07-30 at 11:11, Chris W. Parker wrote: Johnny Martinez mailto:[EMAIL PROTECTED] on Wednesday, July 30, 2003 11:07 AM said: Google spidered the web view to the list and is indexing our email addresses. Any chance you can edit the code to change [EMAIL PROTECTED] to show as user at domain dot com as many of the public message boards do? This will help reduce the spam we get. Until all the email harvesters start to recognize those types of email addresses too. Chris. 'Until' is a bit optimistic. They've been doing that for quite some time now. :) -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] List Administrator
On Wed, 2003-07-30 at 11:07, Johnny Martinez wrote: List Administrator, Google spidered the web view to the list and is indexing our email addresses. Any chance you can edit the code to change [EMAIL PROTECTED] to show as user at domain dot com as many of the public message boards do? This will help reduce the spam we get. Johnny The problem is that this list is archived in a zillion places, and the list moderators don't have any control over the archives. It's up to the individual archive maintainers to deal with this kind of thing. For instance, marc.theaimsgroup.com, phpbuilder.com, and anybody who runs an NNTP web interface which includes this list--just to name a few--have web-accessible archives of this list, and are unaffiliated with the PHP group. -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] I'm really getting annoyed with PHP
On Thu, 2003-07-24 at 20:24, Beauford.2005 wrote: It's obvious though that PHP can not handle it. This is why I am forced to use javascript. I have already spent a week on this and am not going to waste any further time. I have posted all my code and if someone can see a problem I'll look at it, but it just ain't worth the effort at this point. Again, post a script which displays the problem. I've only seen little snippets which do not consitute a working example. It will be seen by many and fixed within minutes. I have had this functionality active every day for years over many different version of PHP in many different environments. The good news is that the problem is not with PHP. That means it's the code, which is easy to fix. -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] I'm really getting annoyed with PHP
On Thu, 2003-07-24 at 04:18, Comex wrote: [EMAIL PROTECTED] Lars Torben Wilson: On Wed, 2003-07-23 at 18:21, Daryl Meese wrote: Well, I know I am not running the latest version of PHP but I don't believe this is accurate. I believe PHP case sensitivity is based on the os that processes the file. Can anyone clear this up. Daryl OK: you're mistaken. If you're correct, it's a bug. I'm pretty sure we would have heard about it by now. :) But give it a try and post your results (I don't have a Win PHP box set up right now, myself). PHP 4.3.2 and 5.0.0b1 on Windows ?php $a = set; print '$A is '; print isset($A) ? 'set' : 'unset'; print 'br'; print '$a is '; print isset($a) ? 'set' : 'unset'; ? $A is unset $a is set Thanks. The same file on Linux PHP 4.3.2 produces the same output. The manual is correct: variable names in PHP are case-sensitive, full stop. It is not dependent upon the OS. This is explained here: http://www.php.net/manual/en/language.variables.php Thanks for the Win test, Comex! Cheers, Torben -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP should know my data!
On Thu, 2003-07-24 at 15:04, John Manko wrote: I just wrote a web app, but I'm completely disgusted with PHP. The application works great, but PHP is not smart enough to know what data belongs in my database. Really, I have to enter the stuff in myself. I spent 2 long days writing this (sweating and crying), and you mean to tell me that it doesn't auto-populate my database information? Come on, people! Data entry is the thing of the past! Maybe I'll convert my codebase to COBOL or something. At least, it has proven experience with user data! Sometimes I wonder how long this innovative technology will last when there are incompetent languages like PHP, Perl, and Java. Color me disappointed. John Manko IT Professional I'm not sure what you mean that PHP should automatically know what goes into the database, but if you post a detailed description of the problem you're facing, chances are that someone (or several someones, more likely) will provide suggestion to help you out. Feel free to post details if you would like a hand with it. -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP should know my data!
On Thu, 2003-07-24 at 15:24, John Manko wrote: LOL :) - Now that's funny! Robert Cummings wrote: Unfortunately I don't think some people got the joke. Next thing you know their going to complain that PHP should have told them the punchline ;) Cheers, Rob. Oh fer Pete's sake. lol--got me. The sad thing is that sometimes things get to a point on the list where this sort of thing would seem likely... -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global variable question question
On Wed, 2003-07-23 at 12:19, Jason Giangrande wrote: When registered globals is set to off this does not effect the $PHP_SELF variable right? In other words I should be able to call $PHP_SELF with out having to do this $_SERVER['PHP_SELF'], right? Thanks, Jason Giangrande Without going into why you didn't read the manual or just try it, the answer is 'wrong'. ;) If register_globals is off, $_SERVER['PHP_SELF'] is what you will need. Good luck, Torben -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] I'm really getting annoyed with PHP
On Thu, 2003-07-24 at 12:41, Beauford.2005 wrote: Yes, I'm still screwing around with this stupid redirection thing, and either I'm just a total idiot or there are some serious problems with PHP. I have now tried to do it another way and - yes - you guessed it. It does not work. I doubt rather a lot that either of these things is true. But given that header redirects work fine for everybody but you (well, that's overstating it, but I bet that's what it feels like)...something is hooped. If you send me the smallest complete script which manifests the problem, I will check it out for you. The code you've posted so far looks OK. I mean really, it can not be this hard to redirect a user to another page. If it is, then I must look into using something else as I just can't be wasting days and days on one minor detail that should take 30 seconds to complete. If anyone has some concrete suggestion on how to get this to work It would be greatly appreciated. In the mean time I have given up on it as I am just totally pissed off at it. TIA -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] I'm really getting annoyed with PHP
On Thu, 2003-07-24 at 15:12, Beauford.2005 wrote: FORM onSubmit=return checkrequired(this) ACTION=season_write.php action=post name=seasons Try ACTION=/season_write.php instead. What happens? -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] I'm really getting annoyed with PHP
On Wed, 2003-07-23 at 18:21, Daryl Meese wrote: Well, I know I am not running the latest version of PHP but I don't believe this is accurate. I believe PHP case sensitivity is based on the os that processes the file. Can anyone clear this up. Daryl OK: you're mistaken. If you're correct, it's a bug. I'm pretty sure we would have heard about it by now. :) But give it a try and post your results (I don't have a Win PHP box set up right now, myself). -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] list server problem
On Sun, 2003-07-20 at 11:04, Andu wrote: --On Monday, July 21, 2003 01:34:11 +0800 Jason Wong [EMAIL PROTECTED] wrote: On Monday 21 July 2003 00:39, Andu wrote: The executive summary is that there is nothing to be fixed. If you're using a less than adequate mail client which does not understand the mailing list info contained in the headers then you should either change clients or, even easier, just add the mailing list address into your address book. Nonsense, all clients understand reply-to if it's there and that is the obligation of the sender which in this case is the list server not my client. Please read the archives. There's several thousand emails in there, give me a subject or something. I already attempted to do that but the search only takes 2 words, it looks like and chances I use the relevant ones are low, just spent some time without any relevant success. I searched using the terms 'list' and 'reply-to', and the thread was on the first page. But it depends on which archive you're searching, of course, and you didn't specify which one you are looking in. The one I used was http://marc.theaimsgroup.com/?l=php-generalr=1w=2 So what you're saying is that all the lists i've been on in the past 7-8 years were doing it wrong but this one doesn't. This is correct. Many lists have used reply-to in a broken fashion, and many people have become trained to expect this behaviour. Please do a search on the net for a document entitled 'Reply-to Considered Harmful' for more discussion on the topic. I've seen arguments about this every couple of months for the last 10 years and quite frankly am too sick of it to bother anymore. (And no, I don't run this list, I just work on the manual.) The list is not the originator of my message but an inteligent list server knows that the vast majority of the clients want to reply to the list not the originator of the message. This is not a valid assumption. I would consider any list broken which tried to outthink my decisions like that. It is the mail client's job (or the list subscriber to be more precise) to direct a reply to the appropriate place and not the list's responsibility to second-guess where a reply should be directed. So what do I do if I have one account only? Should I keep changing the Reply-To for each email I send so that replies to other unrelated mail don't end up on php list? The list should second-guess members of the list want to reply to the list 99% of the time without being wrong. I disagree. Oddly, I've known people who have been operating using the correct methodology for well over a decade with no ill effects. -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array key names - can they be called as strings?
On Thu, 2003-07-17 at 14:38, Mike Morton wrote: Perhaps I was not that clear on the subject :) I have the following array: $SAVEVARS[headerimage]=$_POST[headerimage]; $SAVEVARS[backgroundimage]=$_POST[backgroundimage]; I want to iterate through it to save to a database config: Forach($SAVEVARS as $whatever) { $query=update table set $whatever=$whatever[$whatever]; } Where the 'set $whatever' would become 'set headerimage' and '=$whatever[$whatever]' would become the value that was posted through and set on the line above. The question is the - the assigned string key - is there a way to retrieve that in a loop? Foreach, for, while or otherwise? -- Cheers Mike Morton foreach ($SAVEVARS as $key = $value) { $query = update table set $key = '$value'; } Also, unless you have constants named 'headerimage' and 'backgroundimage', you should quote the array subscripts: $SAVEVARS['headerimage'] = $_POST['headerimage']; etc. See the manual for why: http://www.php.net/manual/en/language.types.array.php#language.types.array.donts Hope this helps, Torben -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Too much of $GLOBALS[] a problem??
On Thu, 2003-07-17 at 18:35, Ow Mun Heng wrote: Hi All, Just a quick question on this. In my scripts, I'm using A LOT Of $GLOBALS['my_parameter'] to get the declared values/string. 1 example below : The only real problem is if you ever want to use that code in anything else. Using lots of globals will make that harder, since it will mean that you cannot simply lift that function out and drop it into some other chunk of code without making sure that the new global space contains all those globals, and that they contain what you expect. This is called 'tightly-coupled' code. It's just harder to reuse. 'Loosely-coupled' code relied much less on the environment around it. It would typically receive its values through an argument list, array of values it needs, or perhaps by being a method in a class which has attribute values for all of the necessary stuff. Other than that, it's not a huge issue. -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Too much of $GLOBALS[] a problem??
On Thu, 2003-07-17 at 21:10, Ow Mun Heng wrote: 'Loosely-coupled' code relied much less on the environment around it. It would typically receive its values through an argument list, array of values it needs, or perhaps by being a method in a class which has attribute values for all of the necessary stuff. The $GLOBALS['parameter'] is actually defined in ONE(a config file that houses all the parameters and another a language file) place where it can be changed. So, i would say that's an argument list, is it not? No, it's a configuration file. An argument list is the bit between the parentheses when you write a function call: $retval = some_func($this, $is, $the, $argument, $list); If your config file had all of those variables in an array or something, and you passed that array to your function, *that* would be an argument list. See below: config.php: ?php $config = array('logout' = 1, 'overall_summary' = 'Here is the summary', etc); ? script.php: ?php include('config.php'); display_menu_html($config); ? Problem solved. The only thing left which can conflict is the name $config, and you could solve that by calling it something you're sure nobody else will be using (maybe $_omh_config or something). Now, you can lift your config file and display_menu_html() function and drop them into pretty much any script and be much more sure that you won't have to crawl through all the code making sure there are no variable name conflicts. The other way would be to write a function that obtains that from the argument list. But as I see it, it's basically the same thing? NO? No, because say you want to use this function in another script. First you need to make sure that this new script isn't already using any globals with any of the names you want to use--otherwise, you'll have variable clashes--where you expect one thing to be in $logout, for instance, but the script is using the name $logout for something else, and the value isn't what you expect. Class.. That's not somewhere I would want to venture, not right now anyway. Just starting out. Cheers, Mun Heng, Ow H/M Engineering Western Digital M'sia DID : 03-7870 5168 There was a discussion on this list about programming practices and books about programming--I think last week or the week before. Try a search on the archives. Anyway, there are lot of great books on programming which should help--and excellent and easy-to-read book which covers a lot of things which you *don't* want to have to figure out yourself is 'Code Complete', by Steve McConnell. -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What did I do wrong to cause a parse error?
Hi there, On Thu, 2003-07-10 at 21:53, Phil Powell wrote: foreach ($profileArray[$i][attributes] as $key = $val) { ^^ You should quote the word 'attributes': http://www.php.net/manual/en/language.types.array.php#language.types.array.donts Sorry...that link might wrap. Anyway, I doubt that's the problem... $singleProfileHTML .= $key . =\ . str_replace(', '#039;', str_replace('', 'quot;', $val)) . \\n; } No idea. All I did was copy-paste your code and add a test definition for the other vars, and I just got this: [Script] ?php error_reporting(E_ALL); ini_set('display_errors', true); ini_set('html_errors', true); $profileArray = array('1' = array('attributes' = array('height' = '168 cm', 'weight' = '\'65\' kg'))); $singleProfileHTML = ''; $i = 1; foreach ($profileArray[$i][attributes] as $key = $val) { $singleProfileHTML .= $key . =\ . str_replace(', '#039;', str_replace('', 'quot;', $val)) . \\n; } print_r($singleProfileHTML); ? [Output] Notice: Use of undefined constant attributes - assumed 'attributes' in /home/torben/public_html/phptest/__phplist.html on line 36 height=168 cm weight='65' kg The parsing error occurs in the $singleProfileHTML.. line. I'm completely don't get it; I see absolutely nothing wrong with this, what did I miss? Phil I don't see anything wrong. Perhaps you have a non-printable control character embedded in your code? Try copy-pasting the above code (but quote that array key) and see if that helps. Also, check the code before that line for unclosed quotes and braces/parens or other problems; some parse errors can show up far from where they actually occurred. Other than that, without knowing anything else, it's hard to say off the top of my head. -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] error on array loop through foreach?
On Mon, 2003-07-07 at 21:31, Micah Montoy wrote: It did help and I altered the script a bit. It now reads as: [snip] Now I am receiving the error message of: Warning: Invalid argument supplied for foreach() in c:\inetpub\wwwroot\webpage10\example\u_images\act_load_imgs.php on line 43 Anyone have an idea of what may be causing this? thanks Are you 100% sure that $filename is an array when you give it to foreach? Check to make sure that $filename exists and is an array first. That should help. Good luck, Torben -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Retaining formatting problem
On Tue, 2003-07-08 at 02:29, [EMAIL PROTECTED] wrote: Hello everyone, I have a long running problem that i just want to get covered, I have a standard text box for people to insert long lengths of text. This text box is in a standard input type=text but when I insert it into the database the line returns dissapear, eg this little amount of text will enter like this little amount of text will enter like Please help me it is p!!$$!ng me right off :P Cheers in advance Try this: http://www.php.net/nl2br Good luck, Torben -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] error on array loop through foreach?
On Mon, 2003-07-07 at 00:16, Micah Montoy wrote: I'm using the foreach to loop through a array that is passed from a form. The form has a multiple select field and the field sends a list of selected image locations (i.e. c:\\myimages\\rabbit.gif). All the fields are selected by use of JavaScript before the form is submitted. Anyway, I am getting the error: Hi there, Parse error: parse error, unexpected T_FOREACH in c:\inetpub\wwwroot\webpage10\example\u_images\act_load_imgs.php on line 39 Here is the code that I am using. The foreach statement is line 39. //loop through all the chosen file names and input them individually $count = 0 You need a semicolon at the end of the above line. foreach ($filename as $filevalue){ //get file size function function fsize($file) { $a = array(B, KB, MB); $pos = 0; $size = filesize($file); while ($size = 1024) { $size /= 1024; $pos++; } This function definition should not be inside the foreach(), since the second time the loop executes, it will stop and tell you that you can't redeclare an already defined function (and it was defined on the first loop). I haven't checked the rest of it; try the above ideas and see if they help. Good luck, Torben -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] what licence for documentation ?
On Mon, 2003-07-07 at 05:49, E.D. wrote: Hi, I'd like to know which licence has the documentation. PHP licence ? free licence ? public domain ? other ? In other words, I want to include some parts in a commercial product, can I ? Please answer only if you *know*, I can't go with suppositions. -- E.D. Ask for permission on the phpdoc mailing list, since that's where the people who know are. This is actually a big topic for discussion right now, since there are few people who would like to put the manual into commercial products. Also, simply searching the PHP site for the license will give results very quickly, and it's linked to from the front manual page. Here's the text of the copyright (note that this is NOT the whole of the license: -- Copyright Copyright © 1997 - 2003 by the PHP Documentation Group. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder. Distribution of the work or derivative of the work in any standard (paper) book form is prohibited unless prior permission is obtained from the copyright holder. The members of the PHP Documentation Group are listed on the front page of this manual. In case you would like to contact the group, please write to [EMAIL PROTECTED] The 'Extending PHP 4.0' section of this manual is copyright © 2000 by Zend Technologies, Ltd. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). -- Hope this helps, Torben -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Probs with a form
On Fri, 2003-07-04 at 15:02, LPA wrote: Hey, I must send datas threw a form, but I dont want to have a submit button.. Is there a way to 'simulate' the click of a submit button? Thnx for your help Laurent Hi there, This is really an HTML question, and not a PHP question, but use an input type=image . . . instead and it should work for you. The link below will take you to everything you need to know. http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.4 If you want examples etc, google for something like 'image submit html' and you'll get tons of info. Hope this helps, Torben -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] looping through values from a field? Need hellp.
On Sat, 2003-07-05 at 15:55, Micah Montoy wrote: I have this javascript that enables browsing and selecting of a file. This file location and name are then transferred further down in the form as an option. Multiple files may be chosen as they are just added one below the other. Anyway, when the form is submitted it is only retrieving the last file name from the form. How can I get PHP to return all the values from the select part. Basically this is what is happening: 1. Choose a file input type=file name=viewing onchange=loadImg(); 2. File location and name are displayed in the select name=imgList style=width:350; size=6 multiple/select as option value=c:\images\filename.gifc:\images\filename.gif/option The javascript creates the option and a new option is added and appended when a new file is chosen. 3. Submit form to php script to send location and stuff to database. Anyone have any ideas of how I can get PHP to loop through and pull out each option value? They are separated by a comma. Right now, it only grabs the last file even though all files are highlighted before submission. thanks http://ca2.php.net/manual/en/faq.html.php#faq.html.select-multiple Hope this helps, Torben -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] looping through values from a field? Need hellp.
On Sat, 2003-07-05 at 17:13, Micah Montoya wrote: Ok. I gave it a shot but have run into one other question that I wasn't able to find that was addressed by the article. My select statement looks like this: select name=imgList[] style=width:350; size=6 multiple/select When I create the php file, I am trying something like below but it isn't working and I am receiving an error. What am I not doing? $filename = $_POST[imgList]; for each ($filename as $value) { echo $value; } thanks Impossible to say without know what the error says. :) Anyway, if that code is cut-and-pasted, then 'foreach' should have no space in it. That would cause a parse error. Otherwise, you could be getting a Notice if you're actually passing something in via method=GET but checking the $_POST array instead. -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php