[PHP] Re: MySQL errors in newer PHP 4.2.3
Hello Jocelyn and Steven, Could either or both of you submit a bug report at http://bugs.php.net/? If you follow the instructions there, it will greatly help us in tracking down the issue! Cheers! Zak Greant PHP QA Team -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Query result to an array
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On September 12, 2002 01:55, Christian Ista wrote: $result = mysql_query(...); while( $t = mysql_fetch_row($result) ){ $array[] = $t; } No. I need a 2 dimensions arrays, each line of this array, is the result of one row of the query and each cell of this row is a field from the select. Did you test the code? :) Example, the query return 2 row and 3 fields for each row : Christian, Ista, Belgium zak, PhpNet, Dontknowfrom resulf of SELECT NAME, LASTNAME, COUNTRY FROM MyTable; The code snippet above combined with the above query would create an array of this structure: $array[0][0] = 'Christian'; $array[0][1] = 'Ista'; $array[0][2] = 'Belgium'; $array[1][0] = 'zak'; $array[1][1] = 'PhpNet'; $array[1][2] = 'Canada'; I'd like to put that in an array and later because I use a session array. I'd like via a for loop access these data by echo(MyArray[1][1]); result is PhpNet echo(MyArray[0][2]); result is Belgium echo(MyArray[1][0]); result is zak Is it clearer now ? Cheers! - --zak -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9gD/1b6QONwsK8bIRAmm7AJ41PUo2zVmFwN/vfvTr4j6Fze/NdwCbBPZm bWnEPyBj+bKQsnQ2bg9HZ7E= =q8vy -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] unless something...
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On September 12, 2002 09:47, Magnus Solvang wrote: I'm used to the unless-statement in perl... How do I do this: if string A or B are NOT in string C, then do something and quit. In perl, I would do this: unless ($c =~ /$a|$b/) { blabla exit 0 } ... and in the more verbose PHP you could say if( ! preg_match(/$a|$b/, $c) ) { blah blah blah exit(0); } Cheers! --zak -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9gSNrb6QONwsK8bIRAnIiAKCPcmTiSO+7G4dwt9pQ0LyXnd/o7wCgiIiX YRogR4f45nZLdGioazfwvAo= =PxCf -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Query result to an array
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On September 11, 2002 14:12, Christian Ista wrote: Hello, A query return x rows, by rows there are 4 fields. I'd like to put the result in an array, a 2 dimensions array. Could you tell me how to do that ? Something like this may work for you: # Connect to db, make query, etc. while( $temp = mysql_fetch_row($mysql_result_handle) ) { $array[] = array( 'key0' = array( 'keya' = $temp[0], 'keyb' = $temp[1], ), 'key1' = array( 'keya' = $temp[2], 'keyb' = $temp[3], ) ); } Good luck! - --zak -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9f6tAb6QONwsK8bIRAvjKAJwKN0yvbGaztQzZOKYiy22FMqQ5EgCeP3AH 4sGpVTTX6gUJp8fZJ8xXEfQ= =eaeg -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Displaying value different from actual value
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On September 11, 2002 07:57, Dave Rosenberg wrote: I'm not sure this is possible, but here's what I'd like to do: I know that in order for a set of records from MySQL to display in numerical order on a web page, you need to make the column type Integer, but here's my situation: I'm creating a database of contracts that my organization has. Normally, there is a dollar amount on these contracts, and I'd like to be able to sort by that value (therefore the Integer column type). However, we have some fee-based contracts, and I'd like a way to display the amount as Fee Based even though I can't enter this in the database because of the column type. Is there a way in PHP to have it display this although with some kind of if/then statement or something of that sort? Contract A Fee-based Contract B 7 Contract C 1250 Contract D 5 Hi Dave, You can also do this in your SQL query. For example: If your table contains this: +--+-+ | contract | amount | +--+-+ | Jillco | 100 | | Jackco | 1 | | ChrisInc |NULL | +--+-+ The the following select: SELECT contract, IFNULL(amount, Fee Based) amount FROM contracts; will return: Jillco 100 Jackco 1 ChrisincFee Based Cheers! - -- Zak Greant [EMAIL PROTECTED] MySQL Community Advocate Feed the Dolphin! Order MySQL support from the MySQL developers at https://order.mysql.com/?ref=mzgr Gosh, Batman! The nobility of the almost-human porpoise. --Robin -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9f6iab6QONwsK8bIRAjoJAJ9rswcUKNzR5z9wD7HaKqJ42raiwgCeOzVs TMSVwY5J18Y3zeEmRut9Wyg= =G1gi -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ucwords()? and åäö
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Here is a quick replacement script* for ucwords() that can be made to handle accented characters or interesting casing rules. It is a bit uppercase happy - - uppercasing any letter that comes after a non-letter character. *(Taken from the PHP Functions Essential Reference (http://fooassociates.com/phpfer/)) ?php function custom_ucwords($map, $string) { // A state variable that tracks if we are inside // or outside a block of word characters $inside_word = TRUE; for ($index = 0; $index strlen($string); ++$index) { // If the current character is a key for the map array, // we know that the current character is a word character $is_chr = isset($map[$string[$index]]); /* If the last character was not a word character * but the current character is, convert the * current character to uppercase */ if (! $inside_word $is_chr) { $string[$index] = $map[$string[$index]]; } // Track whether this character is a word or a non-word character // for the next iteration of the loop $inside_word = $is_chr; } return $string; } // A map for English characters $map = array( 'a' = 'A', 'b' = 'B', 'c' = 'C', 'd' = 'D', 'e' = 'E', 'f' = 'F', 'g' = 'G', 'h' = 'H', 'i' = 'I', 'j' = 'J', 'k' = 'K', 'l' = 'L', 'm' = 'M', 'n' = 'N', 'o' = 'O', 'p' = 'P', 'q' = 'Q', 'r' = 'R', 's' = 'S', 't' = 'T', 'u' = 'U', 'v' = 'V', 'w' = 'W', 'x' = 'X', 'y' = 'Y', 'z' = 'Z' ); $string = _JABBERWOCKY_ and, has thou slain the jabberwock?br / come to my arms, my beamish boy!br / o frabjous day! callooh! callay!br / he chortled in his joy.br / _JABBERWOCKY_; echo custom_ucwords($map, $string); ? Cheers! - --zak On September 11, 2002 08:27, Ville Mattila wrote: I can't say correct answer to this, but want also notify that strtoupper() -function doesn't affect to those special charters å, ä and ö that are very common in Finnish language. Ville -Original Message- From: Tommi Virtanen [mailto:[EMAIL PROTECTED]] Sent: 11. syyskuuta 2002 17:14 To: [EMAIL PROTECTED] Subject: [PHP] ucwords()? Hi! I'll try to convert field first char to upper by using ucwords(). Well, this doesn't seem to work correct. Well maybe error came, because that characteres are not standard (they are special characterers, finnish language). Example: $work_text = perhepäivähoitaja; $work_text = ucwords (strtolower ($work_text); print $work_name - PerhepäIväHoitaja). Every char after finnish-ä is upper. How I can correct this error?? gustavus -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9f6nlb6QONwsK8bIRAhANAJ9Xab9JmsjKxlp+KF01822QmK8zFQCbBXW+ 92J2XRJgKmRXRAlhp7QbwTM= =QEMR -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Query result to an array
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On September 11, 2002 15:05, Christian Ista wrote: while( $temp = mysql_fetch_row($mysql_result_handle) ) { $array[] = array( 'key0' = array( 'keya' = $temp[0], 'keyb' = $temp[1], ), 'key1' = array( 'keya' = $temp[2], 'keyb' = $temp[3], ) ); } Hello, Thanks for your help. But that's not work at all. Dear Christian, I assume that you encountered some syntax errors in the code? (or was there another problem?) Anyhow, here is the corrected version while( $temp = mysql_fetch_row($mysql_result_handle) ) { $array[] = array( 'key0' = array( 'keya' = $temp[0], 'keyb' = $temp[1] ), 'key1' = array( 'keya' = $temp[2], 'keyb' = $temp[3] ) ); } - --zak -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9f7K3b6QONwsK8bIRAiATAJ9TPv/28hZiF136TePF5SXTgDinUACgkg6w BJVDvRVsVzqplDLOD/u5u4E= =NbgV -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Query result to an array
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On September 11, 2002 15:21, Christian Ista wrote: while( $temp = mysql_fetch_row($mysql_result_handle) ) { $array[] = array( 'key0' = array( 'keya' = $temp[0], 'keyb' = $temp[1] ), 'key1' = array( 'keya' = $temp[2], 'keyb' = $temp[3] ) ); } I corrected this error myself but that's not work. Why that twice ? (only the key change) 'key0' = array( 'keya' = $temp[0], 'keyb' = $temp[1] ), when I do echo($array[0][1]) I receive array unknown. Ok - if you want a numeric array, then do something like this: array( array( $temp[0], $temp[1] ), array( $temp[1], $temp[2] ) ) --zak -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9f7p3b6QONwsK8bIRAhEpAJ4vU+f/AovqfUkHvdnBf6le47N9AACfdK7K L6Ub877d4ZUwbxSXF6gl9qY= =Vnxt -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Will return break loop?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On September 11, 2002 15:57, Kevin Stone wrote: Really quick question. Will return break a loop inside a function? Example.. myfunc() { while($val=0) { if ($i=128) { return true; //-break or no? } } } I know I could easily figure this out my own but I do not have the means to test it right now. :) Yes - return will break a loop. Cheers! - --zak -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9f74qb6QONwsK8bIRAl+hAJwI4VaBj6IYtbjgHxGQkmq+Lg2iggCfYqOT gsTebidZ6s5u2tc5SC60IyM= =bywU -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Extracting Numbers from a string.
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On September 11, 2002 16:31, Jason Caldwell wrote: I need to extract the numbers only from a field. For example: I have an AMOUNT field and so that I can filter out any user typo's I would like to extract the numbers only. If the user enters $56.55 for example or just $56 then I would like to be able to remove the $ and the . keeping just the 56 or 5655. Can I use eregi_replace() to do this -- I've been trying but it doesn't seem to work right. Hey Jason, You can strip out all non-numeric values with this regular expression: $v = ereg_replace('[^0-9]', '', $v); If you want to keep the decimal place, then use this $v = ereg_replace('[^.0-9]', '', $v); And finally, if you want a regular expression that recognizes monetary values, try this :) $regex = '^' # match the start of a string . '(' # capture any text that matches the regex . '[^0-9]*' # match any character that is not 0-9 . ')' # stop capturing text # Capture match so that we can see if # they used a currency symbol :) . '?' # Optionally match the preceding bracketed text . '(' # capture any text that matches the regex . '[0-9]+' # match an integer number .'|[,.][0-9]{0,2}'# or match a decimal value .'|[0-9]+[,.][0-9]{0,2}' # match integer and decimal .')'# Stop capturing text .'([^0-9]+)'# Capture any trailing text (like USD or CAD) . '?'; # Optionally match the preceding bracketed text if( ereg($regex, $possible_numeric_value, $captured_text) ) { echo $possible_numeric_value might be a monetary value.; var_dump ($captured_text); } else { echo $possible_numeric_value is probably not a monetary value.; } Cheers! - --zak Cheers! -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9f89Cb6QONwsK8bIRAsP4AJ9X6RqWUDJYtagcJvZ37f/UoRJaYgCfbg1S 22ioG6nALcALqXd6xjGxOrQ= =IbP1 -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Query result to an array
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On September 12, 2002 00:56, Christian Ista wrote: array( array( $temp[0], $temp[1] ), array( $temp[1], $temp[2] ) ) I thinks it's not the right way. I have a query, this query can return 1,5,20, 200, ... rows, each row has 5 fields (or more or less). I'd like a 2 dimensions array, one line by row and each cell is a field content of the query. I program in a lot of language C/C++, Java, Delphi, C++Builder, ColdFusion, C# and I don't undersand why the PHP syntax for this kind of think is so complex and not clear. Good Lord! I thought that you wanted to transform an of array query results into a multi-dimensional array. Briefly, you want to do this: $result = mysql_query(...); while( $t = mysql_fetch_row($result) ){ $array[] = $t; } Just read the MySQL section in the PHP manual for more details. Cheers! - --zak -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9gDCIb6QONwsK8bIRAitjAJ0bUVpwvcdbrIayNQFtbfPqtHJSkwCdGmrq OIkNSi0vING+U/+/GgYf/58= =d63f -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Confusing array question ...
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hey John, Actually, you don't seem to far off. You can use a string as a variable name by enclosing the string in ${ }. i.e: ${foo} You should be able to write your loop as something like: foreach($item as $value) { // do some stuff foreach(${prefix${value}suffix} as $v) { // do some stuff } } All of the normal string and variable rules apply, so you can do things like: echo ${ some . $bar .text}; ${prefix${baz}suffix} = 10; ${md5($quux)) = $quux; There is also the added behavior (benefit?) of being able to use odd values for variable names: echo ${ \n\t} = Holy Whitespace, Batman!; HTH! - --zak On September 10, 2002 17:26, John Kelly wrote: Hi, I have 1 primary array called $item containing 20 values each of whose value is part of the name of 20 other arrays containing various number of values. How can I cycle through the primary $item array using a foreach and within that do a for on each of the 20 secondary arrays dynamically inserting each of the 20 secondary array names based on the value of the current primary $item array. Something like the following which obviously does not work. ?php foreach($item as $value) { // do some stuff for($i=0; $icount($beginning_of_array_name_always_the_same . $value . end_of_array_name_always_the_same); $i++) { // do some stuff [chop] -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9frG7b6QONwsK8bIRAlehAJ9ivM6lWm3mu68Gy43vKKPvmZo+CgCfdBdf 5IikMTwLaBwKPvoFDz4CfD0= =CjQD -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] combine 2 integer
On September 9, 2002 03:38, Meltem Demirkus wrote: Hi, I want to add one integer to the end of another , which function can I use?.. Hi Meltem, You can use the concatenation operator (.) ? echo 2 . 4; ? Cheers! --zak -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [PHP-DEV] Resume of my problem
On March 25, 2002 01:50, you wrote: HI, I have a functino write in c, like as: void addvalue ( int a, int b, int *c ) { *c = a + b; } in php ? phpinclude (alexlib); addvalue ( 1, 2, c ); print ( Value c = $c ); ? what the procedure to make this ? To briefly answer your question: You could write code like this: function av ($a, $b, $c) { $c = $a + $b; } For more information, review the section on References and Functions in the PHP manual. --zak -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why?
On March 31, 2002 04:39, Alberto Wagner wrote: Why everyone uses $foo or $foobar as examples? http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=foo --zak -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Multiple Forms
On Sun, 2002-03-03 at 20:31, Martin Towell wrote: 1) not unless you have them opening up a new window for each form 2) combine them into one form Also, this topic is covered quite often on this list Check the list archives for the various solutions people have used http://phpnet/supportphp has a link to the list archive --zak -- PHP General Mailing List (http://wwwphpnet/) To unsubscribe, visit: http://wwwphpnet/unsubphp
Re: [PHP] PHP and XHTML
Hi Daniel, Set short_open_tag = Off in your php.ini file and the problem will go away. --zak Rose, Daniel wrote: Hi, I have looked through the history of the list, and I see that several people have said that PHP fully supports XHTML. I have some problems using XHTML with PHP, namely parse errors, such as a parse error on the first line of every XHTML doc. ?xml version=1.0 encoding=UTF-8? [...] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] count number of email sent to us
Check the list archives - this question gets posed quite often. --zak - Original Message - From: Jack [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, July 18, 2001 1:38 PM Subject: Re: [PHP] count number of email sent to us Yes, that is the point here. We normally use variables from php to do something in php function, how could we use javascript variables to do something in php function? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] count number of email sent to us
Both topics are covered frequently :) --zak Jack wrote: Sorry, It is mistyping here. I mean, we normally use variables from php to do something in javascript function. But how could we use value from variables in javascript function to do something in php function? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Credit card number checker?
Christopher Ostmo wrote: Dr. Evil pressed the little lettered thingies in this order... I know that credit cards have standard formats: There's a standard number of digits, and whether the card is Visa, MC, Amex, etc is encoded in the number, and there is some kind of checksum, and I think the expiration is also encoded in the number. All of this is obvious stuff that anyone designing such a system would do. I'm wondering if anyone can refer me to a site that describes what this format is, so I can write some PHP code that will check to see if a credit card number format is correct. I don't even want to try to run the card through my merchant account if the format is obviously wrong. I assume that banks check the rejection rate on their merchant accounts, and too many bogus cards would not look good. I did a quick search on the web, and there are a vast number of hacker credit card number generators, but that isn't exactly what I'm looking for. Thanks There are many misconceptions about credit cards. I am certainly no expert, but I have done some research in the area. The only 100% certain thing about credit card numbers is the fact that they are 16 numbers. Credit card numbers vary in length based on the type of card. Some cards do not use the same number length all the time. For example: Visa numbers can be 13 characters or 16 characters in length By law, the numbers are supposed to be generated at random and not generated by any kind of algorithm or formula. Doing otherwise would make credit card numbers guessable and therefore inherantly insecure. Credit card numbers are inherently insecure and follow patterns. Most cards have a standard prefix. i.e. The first letter for a Visa number must be 4, Mastercard uses 5, etc.. With most card types, the number must validate via the Luhn formula (See http://webopedia.internet.com/TERM/L/Luhn_formula.html) Most (all?) credit cards now also have a three digit CCV2 number which is only printed on the back of the card and is supposed to be a form of digital signature. Several processing companies are requiring that this number be sent with online transactions. If you're taking credit card payments from untrusted sources, you would be wise to also get the CCV2. Yep. Heck if know how/if they work with the primary card number. :) The only way to pre-check a credit card number is to check for a valid number of characters and the lack of alpha characters. i.e: if (strlen($CCNum) 16 OR !ereg([0-9]{16},$CCNum)) { ... invalid CC code here ... } (or something similar, depending on your initial script) Actually, using the Luhn formula, you can validate most credit card numbers (and Canadian Social Insurance Numbers FTM). I have a script that: - validates credit card numbers - determines the credit card type based on the number - cleans CC numbers before processing (which allows the user to enter spaces for readability, without buggering the validation.) - see http://www.zend.com/codex.php?id=31single=1 Unless it becomes absolutely ridiculous, I don't think that your bank is going to complain for too many bad cards. After all, they're still making money off of you. If they do get upset, you ought to find a new bank. Seriously. Many banks would be very happy to have your business, bad credit card requests and all. Validating cards does reduce the hassle for the customer though. :) --zak -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] explode()
list (,$reqmonth) = explode ('-', $row[5]); --zak - Original Message - From: Adam Plocher [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, July 16, 2001 5:23 PM Subject: [PHP] explode() $reqmonth = ${explode(-,$row[5])}[1]; Is there anyway I can get that to work without having to use multiple lines of code? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Variable name declarations?
Hi Matthew, Set your error_reporting level to E_ALL. The parser will then report the use of undeclared variables. --zak - Original Message - From: Matthew Aznoe [EMAIL PROTECTED] To: php [EMAIL PROTECTED] Sent: Friday, July 13, 2001 2:22 PM Subject: [PHP] Variable name declarations? I have to agree that strong typing is not a good fit with PHP. It really limits the flexibility of the language that is, at least to me, one it its strongest appeals. Often, strong typing can be overly restrictive, and free typing, when combined with good comments and documentation which should go alongside any piece of code, allows much easier development in my experience. However, I do have one complaint about PHP that seems to have a tendency to bite me far too often, and that is the lack of variable declaration. While I do not think the type of the variable should be required, requiring the user to specify which variable names are going to be used I think would be useful. The reason why I believe this is important is in debugging. I have been caught many times misspelling a variable name slightly (ie - ei), and since PHP does no variable name checking, sometimes it takes a while to discover the error. If each variable name had to be declared prior to use, it would eliminate this problem by warning the user each time an undeclared name was used. The syntax could be very simple using constructs that already exist in the langauge. The name would be defined by using the var command somewhere in code prior to the variable being used (as in classes... but here again, the class elements are not limited to those defined). The declaration would reserve only the name of the variable, so the actual type would continue to be free form. Arrays could continue to be created as they are now since only the name of the variable would be checked (you could still have potential problems in associative arrays). Global PHP variables (ie $GLOBALS) would not need to be declared (they would be declared automatically). example: function sum_array( $input_array ) { var $index; var $sum = 0; for( $index = 0; $index count( $input_array ); $index++ ) $sum += $input_array[ $index ]; return $sum; } Potentially, the $index variable could also be declared within the for loop by adding a var before the first index as well. To keep things simple and in line with the current variable scope rules, the scope of the name would be global for the function in which it was defined. I do not know all of the logistics behind the parsing and compilation processes in the PHP engine, but I believe this could be done without too much overhead. It could be an optional feature (controlled from the php.ini file) that could be turned off when released to production to save on performance. If this value was defaulted to off in the release, it would also allow people to upgrade existing code to the new version without having to worry about instantly changing their code to the new paradigm. I do not believe that this would sacrifice very much freedom in the language, and it would certainly make debugging and maintainence easier on the developer. Also, by having all of the variables declared at the top of the functions, it could help commenting by describing the variable name as it is being declared, and it would encourage a better coding style. Does anyone else have any thoughts on this? Matthew Aznoe [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Next Book
Rick wrote: [...] I'd be interested in some good PHP books as well, I feel like I'm in a rut. At first, PHP was all new, and I was learning s much... but now if I think up a task I can visualize how to do it in PHP pretty easily. I know I have a LOT to learn, but I think my problem is I don't know proper programming techniques... I would recommend the PHP Developer's Dictionary - it is high-quality, practical and covers a lot of ground - from basic PHP to advanced PHP to building your own PHP extension. Disclosure: I reviewed the manuscript for the author (as a favor :) [...] --zak -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] High Ascii chars
rm wrote: php3.x We have a large number of people submitting a large number of docs...I'm having a problem with some docs coming through with high ascii characters in the text, apparently the dbm database we're using chokes on some high ascii chars. I need to eliminate characters in the text from 122 to 255. I can't seem to find a simple way to do thisI have a routine, it works but it takes too long, something like; for ($i=122; $i256; $i++){ $textline=str_replace(chr($i),'',$textline) } Anyone know of a better, faster way to filter out these high ASCII characters Hi! Your best option is probably GNU Recode (see the PHP manual and http://www.gnu.org/directory/recode.html) It will allow you to convert 8-bit characters to a 7-bit characters quickly and sanely: converting accented characters to their closest logical equivalent. Note: The method you chose is surprisingly speedy - it is a good 3-4 times faster than most other methods that are similar. However your fastest method for removing the offending characters would be to use preg_replace() - it should be about 4 times faster than the method you chose. --zak -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] error_log not obeyed
Arcady Genkin wrote: [message format fixed] ..s.c.o.t.t.. [EMAIL PROTECTED] writes: I'm trying to send PHP errors into a separate log file. I have the following in php.ini: log_errors = On error_log = /var/www/logs/php-errors.log After apache restarted the errors are now being sent to apache's error log, but not the one I specified. Any ideas? does the directory exist? This is the same directory where Apache writes its own logs. It' only writeable to root, but I thought that the controlling apache process would be responsible for creating the file (controlling apache runs as root). The controlling process is not running PHP however. PHP is probably running as www or nobody. Try writing to /tmp (or some other directory writeable by nobody) does php or apache have the right to create new files in /var/www/logs/? if the file exists, are the permissions set correctly on it? keep in mind that the user that owns apache usually has very limited powers Well, see above. If Apache can write its own logs there, it should be able to write PHP's logs there too, right? No way - totally different things. What worries me is that the logs are directed into apache's error logs. This makes me think that the problem is not with permissions... Any further ideas, anyone? If you really want to write to the same log directory as the apache logs, use PHP's apache_note function to pass data to apache and in your httpd.conf file use a custom log format for the data passed. --zak -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Enter to BR
Use nl2br() --zak - Original Message - From: Joeri Vankelst [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, June 25, 2001 4:16 PM Subject: [PHP] Enter to BR How can I get an Enter typed in a HTML textfield to be inerpreted as a BR or a P tag? Someone sugested I use the split() function, but I wouldn't know how... Joeri Vankelst -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] converting Word documents to something sensible
Hi Phil, There are a few options that may meet your needs: Word2x (http://word2x.alcom.co.uk/) LAOLA (http://user.cs.tu-berlin.de/~schwartz/pmh/) Good Luck!! --zak - Original Message - From: Phil Driscoll [EMAIL PROTECTED] To: Justin Farnsworth [EMAIL PROTECTED] Cc: php general [EMAIL PROTECTED] Sent: Sunday, June 24, 2001 11:39 AM Subject: Re: [PHP] converting Word documents to something sensible On Sunday 24 June 2001 16:32, Justin Farnsworth wrote: Try the latest AbiWord... I've just installed it, but I can't find any obvious way to invoke it at the command line to load a Word file and save out html or rtf. Am I missing something? Also, when I tested the software via its gui and load a Word file from the project I'm working on, the software crashed and exited with a load of panic messages :( Cheers -- Phil Driscoll -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] explode
Richard Kurth wrote: Question about explode this work just perfect $name=what+ever; $name1=explode(+,$name); $fname=$name1[0] ;this has what $lname=$name1[0] ;this has ever But if I pass the info from another page like this a href=whatever.php?name=what+evertest/a $name1=explode(+,$name); $fname=$name1[0] ; this has what ever $lname=$name1[0] ; this has nothing in it $fname has both names in it How come I get this it does not make since Try echo()'ing $name on the page you passed it to. Notice anything different? :) Before you pass values around with a query string, you should prepare them first by processing them with rawurlencode(). --zak -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] passing arrays
Jason Jacobs wrote: Hi all. I'm trying to pass an array to another page, and I'm not having luck. I thought maybe it would do something slick by passing it in the url, but it doesn't. So, how can I pass the array? You can pass an array between pages by using the serialize() and unserialize() functions in conjunction with rawurlencode(). Serializing a variable is kind of like freezing food. You freeze food so that you can store it for later use. Serializing does roughly the same thing for a variable, converting a 'fresh' variable into a string that you can store and then 'thaw' for later use. The basic steps to use serialize to transfer data between pages are: 0.) Page foo.php has an array that it wants to pass to bar.php $array = array ('doe', 'diddy', 'dee', 'dum'); 1.) Serialize the array $serialized_array = serialize ($array); 2.) Make the serialized data safe for transport via http by passing it to rawurlencode() $serialized_array = rawurlencode ($serialized_array); 3.) Pass the serialized array to another page via GET. (You could also use a form and POST) echo The serialized array looks like this: $serialized_arraybr; a href=bar.php?array=?php echo $serialized_array ?Send/a 4.) Unserialize the array at page bar.php (You may need to call stripslashes() on the passed data - review the magic_quotes directives in your php.ini file for more information) $array = unserialize (stripslashes ($array)); 5.) Voilà! Garnish with a 'Powered by PHP Logo' and it is ready to serve. ;) Good Luck! --zak -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] math question
Have you defined the 'pi' constant? If you are trying to use PHP's built-in PI constant, it is named 'M_PI' Perhaps consider increasing your error reporting level so that PHP reports problems like undefined constants - see error_reporting() for more details. --zak - Original Message - From: Julia A. Case [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, June 23, 2001 12:07 AM Subject: [PHP] math question $theta = 15*pi/360; gives a value of 0 for $theta... it should be something like 0.131... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Parse PHP inside a variable
Write your code to a temporary file, include the file and then delete it. ?php // HTML + PHP mixed code $code = b?php echo 'BOO!' ?/b; // Create a temporary file to store the code $file = tempnam ('/tmp', 'eval'); error_log ($code, 3, $file); // include the temp file include ($file); // erase the temp file unlink ($file); ? /* Note - I have not tested the above code, however it should work... :) */ Good luck! --zak - Original Message - From: James Atkinson [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, June 20, 2001 10:08 PM Subject: RE: [PHP] Parse PHP inside a variable I'm in the same boat, I've tried eval() but it dosan't like mixing PHP and HTML code... I've tried the suggestions listed in the php.net manual too to no avail... - James -Original Message- From: Lenar Lõhmus [mailto:[EMAIL PROTECTED]] Sent: June 20, 2001 3:01 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Parse PHP inside a variable maybe function eval()? lenar. Claus Heiko Niesen [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Hello I'm having a variable that contains HTML with embedded PHP code. When I echo it then the PHP code does not get executed. Is there a way I can parse/print the content of my variable? Thanks Claus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] email templates and str_replace
Hi Richard, You are replacing the placeholders in $mail_template, but you are storing the results in $mail_content. $mail_content = str_replace('##fullname##',$fullname,$mail_template); $mail_content = str_replace('##email##',$email,$mail_template); This means that each time you call the str_replace function, you are overwriting what was generated by the previous call to str_replace. Just change $mail_content to $mail_template and everything should work. --zak - Original Message - From: Richard Kurth [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, June 20, 2001 2:32 AM Subject: [PHP] email templates and str_replace I am trying to set up a template for an email program below you will see the test program the $mail_template is pulled from a database that is pre saved when it is saved the Placeholders are filled in using str_replace. that is what I want it to do. But it does not work. What am I missing hear. $mail_template= html head titleWeb Hosting At ##hostdomain## /title /head body bgcolor='#C4C9DB' font size='4' color='#008080'strongDear ##fullname## /strong/font brbr font size='4' color='#008080'strongYour webhosting account has been created. Please use the following data to log in to ##domain## /strong/font br font size='4' color='#008080' strongul type=square liDomain:##domain## /li liIP-Address: ##ip## /li liUsername: ##username##/li liPassword: ##password##/li liMysql Database: ##userdatabase## /li liMysql Username: ##newuser## /li liMysql Password: ##newuserpass## /li /ul /strong /font font size='4' color='#008080'strongThanks for choosing ##hostdomain## br Any Questions e-mail ##sales##@##hostdomain##/strong /font /body /html ; /* message*/ //$mail_template = $message; $fullname=Richard Kurth; $email=[EMAIL PROTECTED]; $hostdomain=northwesthost.com; $hostname=www; $domain=twohot; $tld=.com; $baseip=234.444.45.444; $username=rkurth; $password=boat; $userdatabase=twohot; $newuser=twohot; $newuserpass=twohot; $sales=sales; $domainname=$hostname . . . $domain . $tld; $mail_content = str_replace('##fullname##',$fullname,$mail_template); $mail_content = str_replace('##email##',$email,$mail_template); $mail_content = str_replace('##domain##',$domainname,$mail_template); $mail_content = str_replace('##ip##',$baseip,$mail_template); $mail_content = str_replace('##username##',$username,$mail_template); $mail_content = str_replace('##password##',$password,$mail_template); $mail_content = str_replace('##userdatabase##',$userdatabase,$mail_template); $mail_content = str_replace('##newuser##',$newuser,$mail_template); $mail_content = str_replace('##newuserpass##',$newuserpass,$mail_template); $mail_content = str_replace('##hostdomain##',$hostdomain,$mail_template); $mail_content = str_replace('##sales##',$sales,$mail_template); /* and now mail it */ /* recipients */ $recipient = $fullname $email ; //header $headers .=From: Sales Department [EMAIL PROTECTED] \n; $headers .= reply-To:$from\nX-Mailer: PHP/ .phpversion(). \n; $headers .= Content-Type: text/html; charset=iso-8859-1\n; //subject $subject1 = $subject; //mail($recipient, $subject1, $mail_content, $headers); //print $recipient, $subject1, $mail_content, $headers; echo $mail_content; Best regards, Richard mailto:[EMAIL PROTECTED]
Re: [PHP] cookies
Hi Jon, Dealing with expiry dates and cookies is often a PITA! Rasmus suggested a way around this a few weeks ago - here is a rehash of what he said: Do this: setcookie ('expiry', time ()); This call will have created a session cookie - this means that the session will expire when the browser closes the client. Now you have a cookie var called expiry that has the unix timestamp of when the user first accessed the site. Check this value when deciding to expire the user's session. ie. $timeout = 3600;// Set an expiry date of an hour if ($expiry + $timeout time ()) { // handle that the cookie has expired } (Actually, you easily do this with sessions too.) HTH, --zak Jon Yaggie wrote: [...] I have set up a user login so that it will assign a cookie for one hour - setcookie(cookie_id, $id, time()+3600); The manner in which i suse the expiration is copied form the manual but i have actually tried several alteratives. The problem is the expiration works perfectly locally (i am running apache 1.3 for windows) but once i upload it (linux red hat 5.2 (why so old i dont know)/ apache 1.3.19.) The expiration will not work on my browser(s) unless i increase the expiration to +5000 or above. My client tests it using the same version of IE i have and it will not set the cookie still at +5000 for him. Now i understand from browser to browser there can be differences but why can i set a cookie for +200 locally but not for less than +5000 uploaded when i am most certainly checking it with the same browser (IE 5.5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] PHP AND SSI
Use PHP's include() function. See the online manual for details. --zak - Original Message - From: Shashwat [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, May 23, 2001 4:07 AM Subject: [PHP] PHP AND SSI How can I run SSI commands like !--#include file=desk.htm-- etc. in PHP files... as ASP supports it.. I have Apache on Linux Server with PHP 4 installed Shashwat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] ftp_put
Ensure that the user that PHP is running as has permissions to read the file. --zak - Original Message - From: Jon A [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, May 21, 2001 10:36 AM Subject: [PHP] ftp_put Hi, all. I try to do a file upload using the ftp_put function, where the source file is a string from a browse field When I try to do the upload php says that there is an error opening the local file. Does any of you know how to solve this problem? thanks in advance, Jon A -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] All of a sudden I get Warning: Bad arguments to implode() in busca_01.php on line 133
Sounds like you are trying to implode a non-existant array. Change your code to handle an empty or missing array. ie. - Original Message - From: Martin Cabrera Diaubalick [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, May 22, 2001 2:41 AM Subject: [PHP] All of a sudden I get Warning: Bad arguments to implode() in busca_01.php on line 133 Hello Everyone! This is my code if (count($array_id)==1) { $string_id=$array_id; } else { $string_id= implode(:,$array_id); } I've been testing it for three days and never had an error, now it comes and goes. Do you know what could be wrong? $array_id is an array of integers Thanks in advance -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] All of a sudden I get Warning: Bad arguments to implode() in busca_01.php on line 133
ie. Oops! Hit the right keys at the wrong time! :) if (! count ($array_id)) { echo '$array_id is empty or not set.'; } else if (1 == count($array_id)) { $string_id=$array_id; } else { $string_id= implode(:,$array_id); } --zak -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Problem using unpack
$playerdata = unpack('czero/A'.$length.'one/itwo/fthree/A*four', $rest); Good Luck! --Zak - Original Message - From: Craig Vincent [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, May 20, 2001 4:00 AM Subject: [PHP] Problem using unpack I'm current trying to use PHP's unpack feature to decode a binary string and am running into a problem. Here is the unpack command I am using $playerdata = unpack(czero/A$lengthone/itwo/fthree/A*four, $rest); basically it is setup so that the hash created has 5 key/value pairs named zero, one, two, three and four. However my problem is with the second key/value pair. Since the information I need for the second field is dynamic I need to be able to set a variable there to tell PHP exactly how many characters are to be parsed for that field. So say $length = 5 right now the command would be translated by PHP as $playerdata = unpack(czero/A5one/itwo/fthree/A*four, $rest); At least that's what I need =) The problem I'm experiencing right now is that PHP translates the variable as $lengthone instead of just $length which of course always results in 0 and then causes the data to be parsed incorrectly. I cannot use whitespace to separate $length and one as then the unpack feature breaks down thinking that whitespace should be in the string I'm unpacking which messes things up as well. Any suggestions/tips for handling this problem would be much appreciated =) I've been plagued with this problem for a few days now and I'm having no luck =/ Sincerely, Craig Vincent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Re: [PHP-DEV] Fork() in php?
Manuel wrote: [...] Since Zeev and Andi seem to be currently the most capable developers to bring multi-threading capability to PHP because they developed PHP current engine - Zend, my question still goes for them. After all they always seemed more reasonable and opened to my suggestions than you. Manuel, irritating Rasmus is not likely to make Andi, Zeev or any of the other developers more interested in helping you. If you want to ask about a possible feature, mail the PHP-DEV list or try mailing the PHP group. --zak -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Finding if a number is in the range
Or just use a simple chain of if statements :) if ($num = 200 $num = 299) { echo $num is between 200 and 299; } else if ($num =1000 $num = 2263) { echo $num is between 1000 and 2263; } else if ($num =2264 $num = 2499) { echo $num is between 2264 and 2499; } else { echo $num is not between 200 and 299, 1000 and 2263 or 2264 and 2499; } If you have a large number of these to do, you could store your upper and lower bounds in an array and use a loop to process the bounds. ie. // set up our bounds $bounds = array ( -10, -1, 0, 199, 200, 299, 1000, 2263, 2264, 2499 ); // make sure that we have a matched sets of bounds // the bounds array should have at least 2 elements // and the remainer (modulus) of $count / 2 should be 0 $count = count ($bounds); $count 1 AND 0 === ($count % 2) OR die ('The $bounds array must contain one or more matched elements.'); for ($index = 0; $index $count; $index += 2) { if ($number = $bounds[$index] $number = $bounds[$index + 1]) { $between = sprintf (%s is between %s and %s., $number, $bounds[$index], $bounds[$index + 1]); break; } } if (isset ($between)) { echo $between; } else { // join the bounds into a string separated by .. $bounds = join ('..', $bounds); // convert every second set of .. to br $bounds = ereg_replace ('([^.]+\.\.[^.]+)\.\.', '\1br', $bounds); echo Number $number not found with any of the specified ranges:blockquote$bounds/blockquote; } --zak - Original Message - From: MaD dUCK [EMAIL PROTECTED] To: Joseph Blythe [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Thursday, May 17, 2001 7:53 PM Subject: Re: [PHP] Finding if a number is in the range also sprach Joseph Blythe (on Fri, 18 May 2001 11:12:23AM +0930): How do I find if a number is in a range example: assuming that the ranges are continuous, make an array of the first number for each range and then implement a custom binary search for O(lg n) performance. martin; (greetings from the heart of the sun.) \ echo mailto: !#^.*|tr * mailto:; net@madduck -- i wish there was a knob on the tv to turn up the intelligence. there's a knob called 'brightness', but it doesn't seem to work. -- gallagher -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Finding if a number is in the range
MaD dUCK wrote: also sprach Zak Greant (on Thu, 17 May 2001 09:35:18PM -0600): Or just use a simple chain of if statements :) yeah, but that's so O(n) ! i can do in O(lg n) or, given n CREW processors, in O(1) time! yes, i have just finished my computational theory and computer algorithms honors exam. Do you really need a chainsaw to cut a piece of cake? ;) --zak -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Binary Data File reading
Try using unpack() --zak - Original Message - From: Chris Mattmann [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, May 10, 2001 2:54 PM Subject: [PHP] Binary Data File reading Hi there- Does anyone have any clue as to what may be causing this problem. I am trying to read from a binary data value that has temperature values stored in it in short integer format. So basically, for every 2 bytes of binary data, that value in short integer is the temperature value. I have written a simple C program to read in the values from the out.bin binary data file I have, and echo them back to the console: It prints out the correct values, here is the C program that I used: #includestdio.h void main(void) { FILE *fin; short buffer[1]; int num_read; fin = fopen(out.bin,r); num_read=1; while(num_read0) { num_read = fread(buffer, sizeof(short), 1, fin); printf(%d,,buffer[0]); } fclose(fin); return(1); } I am trying to write a php file to do the exact same thing, except instead of printing out the values, I'm going to store them in an array. Anyways, the php script I've written looks like this: ?php $fp = fopen(out.bin,rb); $str = fread($fp,2); while($str) { $str = (int)$str; printf(%d,,$str); $str = fread($fp,2); } ? The output I get from the php script is complete garble(a whole bunch of 0's, some 1's, some random int values, etc. I know that PHP doesn't exactly have a short int type, i know that their integers are actually stored in the C LONG_INT type, which are 8 byte integers. Do you think that this may be affecting my script, and if it is, does anyone know of any workarounds? Your help would be greatly appreciated. Thanks in advance. --- Chris Mattmann Science Data Management and Archiving [EMAIL PROTECTED] NASA-JPLPasadena, CA 91109-8099 Office: 300-324C Phone: 818-354-8810 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Mysql sequence help (OOT)
Use an auto_increment field. ie. create table foo ( id mediumint unsigned not null auto_increment primary key, namechar (16) not null, ... ) --zak - Original Message - From: Reuben D Budiardja [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, May 10, 2001 9:41 PM Subject: [PHP] Mysql sequence help (OOT) Hello, Sorry for a litle bit out of topic. But can anyone tell me how to create sequence in mysql? For example, if I have table with column ID, NAME. I want ID to be incremented by one (say starting from 100) everytime I insert a new row to the table. How can I do that in mysql? I'm only use to Oracle, and tried to find it in mysql.com, but has not yet succed. And I'm a bit under time pressure. Thanks for any help in advance. Reuben D. Budiardja -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] How to read a web page and analyze but not display it
Use fopen() or file() --zak - Original Message - From: Dexter [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, May 08, 2001 4:27 PM Subject: [PHP] How to read a web page and analyze but not display it hi PHP 'sters, How to read a web page and analyze but not display it using PHP. Thanks Dexter. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Refreshing multiple frames?
You are going to need Javascript to do this. --zak - Original Message - From: Brandon Orther [EMAIL PROTECTED] To: PHP User Group [EMAIL PROTECTED] Sent: Monday, May 07, 2001 5:19 PM Subject: [PHP] Refreshing multiple frames? Hello, I am using php with frames for a menu bar. In one frame I have a menu. When the link is clicked on the menu I would like two frames to be updated. Is there a way to do this? Brandon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Decoding .txt attachments
The file is likely uuencoded, AFAIK PHP does not have a built-in function to handle this. IIRC there is a function on http://px.sklar.com/ that does this. --zak - Original Message - From: ~~~i LeoNid ~~ [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, May 07, 2001 12:06 AM Subject: [PHP] Decoding .txt attachments Hello PHP-ers - General`s:), (How)Is it possible to decode text file attachments starting with begin 644. I tried base64_decode(); with no joy (stick:). imap_base64 (); is not defined on my system. Is there a function, or just a table with the HARD way of manual decoding possible? Thanks. -- Leo n id -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] HTTP_RAW_POST_DATA
Dmitri Zasypkin wrote: Hi, Could anyone help me with altering PHP sources? Or tell me please where may I ask this question? The problem is when PHP handles a POST request of a known Content-type (e.g. x-www-form-urlencoded), it leaves $HTTP_RAW_POST_DATA blank. I need to alter the sources so that PHP would always put the request data into this variable. This would allow me to handle malformed POST requests. For example, if a client sends a request of Content-type x-www-form-urlencoded and the data is NOT really urlencoded, such request seems to get lost. I can't find the data neither in $HTTP_RAW_POST_DATA, nor in $HTTP_POST_VARS. I figured it would be great if PHP could always set $HTTP_RAW_POST_DATA independently of the Content-type. **WILD GUESS ALERT** If you modify lines 140-150 of php4/main/SAPI.c from: -- if (zend_hash_find(known_post_content_types, content_type, content_type_length+1, (void **) post_entry)==SUCCESS) { SG(request_info).post_entry = post_entry; post_reader_func = post_entry-post_reader; } else { if (!sapi_module.default_post_reader) { sapi_module.sapi_error(E_WARNING, Unsupported content type: '%s', content_type); return; } SG(request_info).post_entry = NULL; post_reader_func = sapi_module.default_post_reader; } -- to: -- SG(request_info).post_entry = NULL; post_reader_func = sapi_module.default_post_reader; -- you *may* get the behavior that you are looking for. --zak -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] HTTP_RAW_POST_DATA
Actually, I am afraid that they won't. To achieve this, break the if/else block up so that both code blocks are called. --zak - Original Message - From: Dmitri Zasypkin [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, May 07, 2001 7:15 AM Subject: Re: [PHP] HTTP_RAW_POST_DATA Zak, Thank you for the answer. Are you sure $HTTP_POST_VARS will be still set after that modification in case of a valid x-www-form-urlencoded POST request? I'm afraid they won't.. Such side effect is very undesirable for me. Anyway thanks. Zak Greant wrote: Dmitri Zasypkin wrote: Hi, Could anyone help me with altering PHP sources? Or tell me please where may I ask this question? The problem is when PHP handles a POST request of a known Content-type (e.g. x-www-form-urlencoded), it leaves $HTTP_RAW_POST_DATA blank. I need to alter the sources so that PHP would always put the request data into this variable. This would allow me to handle malformed POST requests. For example, if a client sends a request of Content-type x-www-form-urlencoded and the data is NOT really urlencoded, such request seems to get lost. I can't find the data neither in $HTTP_RAW_POST_DATA, nor in $HTTP_POST_VARS. I figured it would be great if PHP could always set $HTTP_RAW_POST_DATA independently of the Content-type. **WILD GUESS ALERT** If you modify lines 140-150 of php4/main/SAPI.c from: -- if (zend_hash_find(known_post_content_types, content_type, content_type_length+1, (void **) post_entry)==SUCCESS) { SG(request_info).post_entry = post_entry; post_reader_func = post_entry-post_reader; } else { if (!sapi_module.default_post_reader) { sapi_module.sapi_error(E_WARNING, Unsupported content type: '%s', content_type); return; } SG(request_info).post_entry = NULL; post_reader_func = sapi_module.default_post_reader; } -- to: -- SG(request_info).post_entry = NULL; post_reader_func = sapi_module.default_post_reader; -- you *may* get the behavior that you are looking for. --zak -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Converting a binary integer to a number
Use unpack(): // Grab as many signed 32-bit integers as possible $array = unpack ('l*', $data); --zak - Original Message - From: Siegfried Kettlitz [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, May 07, 2001 12:36 PM Subject: [PHP] Converting a binary integer to a number I have binary data (ie: 0x7b c8 15 0c ) and want to convert it into a 32Bit integer (here: 123456789012). Currently I use this (intel-little-endian): $integer = hexdec( bin2hex( strrev( readpos( $fd,$position,4 ) ) ) ); readpos reads 4 bytes from a file Is there a better, faster or easier way to do the same thing? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] IIS instead of PWS!!! what else can i do..
You may want to try Xitami (www.imatix.com) as a fast/free/open source alternative to the Microsoft products. --zak - Original Message - From: Thomas Edison Jr. [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, May 06, 2001 12:52 AM Subject: [PHP] IIS instead of PWS!!! what else can i do.. i think i'm almost at the verge of giving up...somehow the PWS in my system is ruined forever...i'd done everything..and i mean *EVERYTHING*...but PHP just doesn't seem to be working with my PWS. In fact, even my ASP scripts are not working anymore on PWS. I've uninstalled reinstalled PWS twice already. it's just **%^. anyways, i think i'm gonna be trying out the IIS option. Is IIS ok to work with PHP4? any problems? and is there anywhere on the Internet that i can get IIS 4 from? thankx all yah, T. Edison jr. = Rahul S. Johari (Director) ** Abraxas Technologies Inc. Homepage : http://www.abraxastech.com Email : [EMAIL PROTECTED] Tel : 91-4546512/4522124 *** __ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] IIS instead of PWS!!! what else can i do..
IIRC, it can with some caveats - check the library at xitami.com --zak - Original Message - From: Thomas Edison Jr. [EMAIL PROTECTED] To: Zak Greant [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Sunday, May 06, 2001 1:05 AM Subject: Re: [PHP] IIS instead of PWS!!! what else can i do.. The only reason why i'm opting for pws or IIS is because i need to run ASP scripts on my PC too. I'm an ASP engineer as well and it's my Second major. So i need to work with ASP too. Does Xitami support ASP? and if it doesn't, can u tell me any other web server for the PC which will run ASP PHP both. I do have the Jrun Server installed cause i work with JSP too. I actually need all 3 : PHP, ASP JSP running on my PC. I'm using JRun for JSP, Apache (now, before i was using PWS) for PHP and i need something for ASP now since my PWS is not working. Regards, T. Edison jr. --- Zak Greant [EMAIL PROTECTED] wrote: You may want to try Xitami (www.imatix.com) as a fast/free/open source alternative to the Microsoft products. --zak - Original Message - From: Thomas Edison Jr. [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, May 06, 2001 12:52 AM Subject: [PHP] IIS instead of PWS!!! what else can i do.. i think i'm almost at the verge of giving up...somehow the PWS in my system is ruined forever...i'd done everything..and i mean *EVERYTHING*...but PHP just doesn't seem to be working with my PWS. In fact, even my ASP scripts are not working anymore on PWS. I've uninstalled reinstalled PWS twice already. it's just **%^. anyways, i think i'm gonna be trying out the IIS option. Is IIS ok to work with PHP4? any problems? and is there anywhere on the Internet that i can get IIS 4 from? thankx all yah, T. Edison jr. = Rahul S. Johari (Director) ** Abraxas Technologies Inc. Homepage : http://www.abraxastech.com Email : [EMAIL PROTECTED] Tel : 91-4546512/4522124 *** __ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] = Rahul S. Johari (Director) ** Abraxas Technologies Inc. Homepage : http://www.abraxastech.com Email : [EMAIL PROTECTED] Tel : 91-4546512/4522124 *** __ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] files
Change the permissions of the /etc/passwd file, use safe mode or suExec --zak - Original Message - From: php [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, May 06, 2001 11:14 PM Subject: [PHP] files Good day to you all How can I keep php scripts from reading the /etc/passwd (for example) or any other file? Sincerely, G. Dimitrov -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] PHP using Forms
Use the nl2br() function --zak - Original Message - From: Mike Mike [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, May 04, 2001 8:11 AM Subject: [PHP] PHP using Forms Hello, I have a form field TEXTAREA name=Home ROWS=10 COLS=40? echo $Home ?/TEXTAREA with this data in it: My Home 11 North 5th St St. Paul MN Phone: (555) 555- Fax: (555) 555- E-Mail: [EMAIL PROTECTED] When submited it goes into a mysql database. The problem i'm running into is that the output looks like this after the call from the mysql database to html: My Home 11 North 5th St St. Paul MN Phone: (555) 555- Fax: (555) 555- E-Mail: [EMAIL PROTECTED] How do I get it to print out with line breaks like how I have typed it into the form? Thank you --Mike __ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Strange Question - Please Read This
Set the auto_append_file or auto_prepend_file in the php.ini file. See http://www.php.net/manual/en/configuration.php for more details --zak - Original Message - From: Chris Anderson [EMAIL PROTECTED] To: PHP [EMAIL PROTECTED] Sent: Friday, April 27, 2001 11:50 AM Subject: [PHP] Strange Question - Please Read This Does anyone know how to place code into every file accessed on my server? Kindof like how geocities and countless other hosts manage to add their banners? Chris Anderson aka Null PHP Developer / Nulltech PHP-GTK Tester / gtk.php.net STA Administrator / www.stronger.org DOD Co-Owner / www.dayofdefeat.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-CVS] Change of address
Hello All, Could someone with the needed karma please change my email address in the cvsusers file from [EMAIL PROTECTED] to [EMAIL PROTECTED] Thank you! --zak -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: [PHP-QA] Error in www.php.net (To site admin)
Are you still encountering the error? I don't see it. --zak - Original Message - From: "Yasuo Ohgaki" [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, March 07, 2001 8:06 PM Subject: [PHP-QA] Error in www.php.net (To site admin) There is a error on www.php.net http://www.php.net/manual/browse-errata.php Fatal error: Call to undefined function: spc() in /local/Web/sites/phpweb/manual/browse-errata.php on line 39 I don't know where to report I hope www.php.net admin read this post. Regards, Yasuo Ohgaki -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]