[FAQTS] PHP Knowledge Base Update -- May 13th, 2000

From: Date: Sun, 14 May 2000 02:10:29 +0000
Subject: [FAQTS] PHP Knowledge Base Update -- May 13th, 2000
Groups: php.kb 
Request: Send a blank email to php-kb+get-44@lists.php.net to get a copy of this message
I've finally found some time to do some list summaries into the PHP Knowledge Base: http://php.faqts.com If you see any answers that you can improve please jump in and contribute your changes... cheers, Nathan ## Unanswered Questions ######################################## ------------------------------------------------------------- How do I pass a sting in a url eg. $MyString='Have a nice day' <a href="gretting.php3?greeting=". $MyString This doesn't work as I only get 'have' http://www.faqts.com/knowledge-base/view.phtml/aid/2780 ------------------------------------------------------------- Christian Hope ------------------------------------------------------------- How do get the number of columns in a MySQL query? http://www.faqts.com/knowledge-base/view.phtml/aid/2783 ------------------------------------------------------------- Zlatko Knezevic ------------------------------------------------------------- Help! I can't install PHP4 RC2. I use win98 SE and win-apache 1.3.12. I have entered the information in the apaches httpd.conf http://www.faqts.com/knowledge-base/view.phtml/aid/2799 ------------------------------------------------------------- Emir Musabasic ## New Entries ################################################# ------------------------------------------------------------- I want to create an array that I can access from a various number of PHP scripts, is there any way I can do this without using the post and get form methods? http://www.faqts.com/knowledge-base/view.phtml/aid/2790 ------------------------------------------------------------- Scott Weese http://www.php.net There is a way that you can do this.. But it uses Cookies.. So it REALLY requires that you do not print/echo any HTML code or HTML headers until you set the cookie. Here is the sample code for it.. When you get ready to set the cookie for the array all you have to do is this.. setcookie ($cookiename, serialize(urlencode($arraytosave))); Also Remember, When you use this method of saving a cookie, if you want ALL your pages in your website to be able to access it, you MUST set the path of the cookie to the $DOCROOT of the site. The reason for this is because if you have a script in a subdirectory, when you set cookie information in that script, if the cookie exists, the value will only be active for that script and time. It will NOT overwrite the final resulting value for the rest of the scripts on the site. You can Just simply remedy this by using the following code: setcookie ($cookiename, serialize(urlencode($arraytosave)), "/"); or setcookie ($cookiename, serialize(urlencode($arraytosave)), $DOCROOT); When you want to retrieve the array just use the following line.. $cookiename=unserialize(urldecode($cookiename)); You can also use this method with Classes and Objects.. ------------------------------------------------------------- How do I execute a function when a checkbox is clicked or a value of a combo box is changed using PHP? http://www.faqts.com/knowledge-base/view.phtml/aid/2792 ------------------------------------------------------------- Scott Weese You don't... I know this isn't the answer you were looking for but heres an explanation. The reason you can't do this is because PHP is a Server Side processing program... Not Client side, like JavaScript and the likes. The only thing you can do about this is write your page to post data to a php script. ------------------------------------------------------------- How do you pass a function name as an argument to another function and then call the passed function? This would be similar to a function pointer in C http://www.faqts.com/knowledge-base/view.phtml/aid/2793 ------------------------------------------------------------- Scott Weese You can do it by passing a string value that is the functions name to the desired caller function but you have to make sure the function to be called is defined before the desired caller is, that is, if you are using PHP3... You don't have to worry about what order the functions were declared in PHP4. Heres an example: function destination ($caller) { echo "Destination reached from origin: $caller<br>\n"; } function caller1 ($funcname) { $funcname("caller1"); } destination("main program"); caller1 ("destination"); This should output the following: Destination reached from origin: main program<br> Destination reached from origin: caller1<br> ------------------------------------------------------------- How can I print a dollar sign in a string? How can I format currency properly in PHP? http://www.faqts.com/knowledge-base/view.phtml/aid/2802 ------------------------------------------------------------- Nathan Wallace Alfred Perlstein Printing dollar signs ($) in PHP can be difficult as they are used to denote variables. In a double quoted string (where variables are expanded) you need to escape the dollar sign as \$ like this: $money = sprintf ("%01.2f", $bal_fwd); $statement .= "\nBalance Brought Forward: \$$money\n"; Or, you can use single quoted string concatenated with the variable: $statement .= "\n".'Balance Brought Forward: $'.$money."\n"; Note that the \n newlines also have to be in double quoted strings to be expanded. ------------------------------------------------------------- How can I get the size of a row of a two dimensional array? Can I use sizeof with multi-dimensional arrays? http://www.faqts.com/knowledge-base/view.phtml/aid/2803 ------------------------------------------------------------- Nathan Wallace Jason Brooke Thats simple, when you have a multi-dimensional array, each array-element *is* an array. So, for a two dimensional array like this: $Arr[$i][$j] then: sizeof($Arr[$i]) will tell you how many elements in that particular dimension of the array. ------------------------------------------------------------- How can I turn off PHP execution on a per directory basis? What are the PHP3 and PHP4 directives to stop PHP execution in a directory? http://www.faqts.com/knowledge-base/view.phtml/aid/2804 ------------------------------------------------------------- Nathan Wallace Fredrik Hellström In Apache you can use .htaccess files in the directories you want to affect. There are PHP directives that can be placed in that file. In PHP4 you should use php_flag engine off instead of php3_engine off ------------------------------------------------------------- Does empty return true or false if the given value is zero (0)? Are there any changes to the empty() function from PHP3 to PHP4? http://www.faqts.com/knowledge-base/view.phtml/aid/2805 ------------------------------------------------------------- Nathan Wallace Torben Wilson This works the same for me in PHP 3 and 4 (recent builds). From the manual: int empty(mixed var); Returns false if var is set and has a non-empty or non-zero value; true otherwise. See also isset() and unset(). However, you should note that PHP3 considers a _string_ containing the zero character to be non-empty, whereas PHP4 considers it to be empty. i.e. the following snippet outputs "It's empty" under PHP4, but "It's not empty" under PHP3 (even though '0' evaluates to false under both versions): <?php $test = '0'; if ( empty( $test ) ) { echo "It's empty<br>\n"; } else { echo "It's not empty<br>\n"; } ?> ------------------------------------------------------------- How can I randomly shuffle the contents of an array? http://www.faqts.com/knowledge-base/view.phtml/aid/2806 ------------------------------------------------------------- Nathan Wallace Richard Lynch Here's an easy one off the top of my head: <?php function shuffle($array){ //Randomly arranges elements in the array. //Returns the shuffled array. //This particular algorithm is O(n) //Take care to call srand once, and only once //in any given script. static $srand; if (!isset($srand) || !$srand){ $srand = 1; srand((double) microtime() * 1000000); } $count = count($array); for ($i = 0; $i < $count; $i++){ //Your version of PHP may need a different syntax to //generate a random number between $i and $count //Perhaps rand() % ($count - $i) + $i //More details in the PHP manual under 'rand' function $rindex = rand($i, $count); $temp = $array[$i]; $array[$i] = $array[$rindex]; $array[$rindex] = $temp; } return $array; } ?> ------------------------------------------------------------- What changes were made to the Apache directives? http://www.faqts.com/knowledge-base/view.phtml/aid/2807 ------------------------------------------------------------- Nathan Wallace Matt McClanahan The Apache directive interface for PHP has been streamlined a great deal with version 4. For more information, see http://www.php.net/manual/html/configuration.html To answer your question, I imagine the directive you're after is php_admin_value asp_tags <boolean> ------------------------------------------------------------- Does PHP work with Lotus Notes? http://www.faqts.com/knowledge-base/view.phtml/aid/2808 ------------------------------------------------------------- Nathan Wallace Richard Lynch As far as I know, PHP does not run with Lotus Notes. This question has come up before, though, so maybe one of the askers has started a port. Check the mailing list archives. How to make it would be to download the PHP source tarball, then get ahold of any Lotus Notes API/source/documentation you can (good luck) and start figuring out how the two could relate... Compare the Notes API to the various database APIs (MySQL, MS-SQL, ODBC, etc) and look for commonalities -- The database functions in PHP are thinly disguised wrappers around the underlying database API. http://cvs.php.net may be useful.

« previous php.kb (#44) next »