PHP Knowledge Base Update -- August 11th, 1999

From: Date: Thu, 12 Aug 1999 09:13:52 +0000
Subject: PHP Knowledge Base Update -- August 11th, 1999
Groups: php.kb 
Request: Send a blank email to php-kb+get-26@lists.php.net to get a copy of this message
I've just added a couple of new PHP related instruction sets to e-gineer: Installing IMAP 4.x for PHP 3.0.x with Apache 1.3.x on Red Hat 5.x Installing IMP 2.0.x for PHP 3.0.x with Apache 1.3.x on Red Hat 5.x They are available with my other instruction sets at: <http://www.e-gineer.com/e-gineer/instructions/index.phtml> Cheers, Nathan ------------------------------------------------------------ How can I generate a unique value in PHP? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/580 ------------------------------------------------------------ John Coggeshall uniqid() will work just fine. It generates a unique key based on microtime. http://www.php.net/manual/function.uniqid.php3 ------------------------------------------------------------ How do I connect to an ODBC database? Where can I get an example of an ODBC session? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/581 ------------------------------------------------------------ Riley Breiddal Code for an ODBC connection: $myDB = odbc_connect("Movies","",""); $query = "SELECT * FROM MovieList"; $result = odbc_exec($myDB, $query); $report = odbc_fetch_row($result); echo odbc_result($result, 1); odbc_close($myDB); This code would goto whichever database you have declared as "Movies" in your System DSN list with no login or password. Then using $query (if you don't know SQL, write your query using that Access Design View, then switch to SQL View, and it'll show you the 'code' for it). The rest is straightforward, just prints out the first field of the first row in the database. About the DSN's, if you operate your server, (I'm assuming your on NT :) just goto ODBC Data Sources in Control Panel and add your database to System DSN. Driver = Access. Data Source Name = (in this example) "Movies". ------------------------------------------------------------ How I can limit use of PHP to only one directory of a website? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/583 ------------------------------------------------------------ Teodor Cimpoesu well my guess is: on server wide config <IfModule mod_php3.c> php3_engine off </IfModule> <IfModule mod_php4.c> php_admin_flag engine off </IfModule> In your directory(or ries) <Directory foo> <IfModule mod_php3.c> php3_engine on </IfModule> <IfModule mod_php4.c> php_admin_flag engine on </IfModule> </Directory> ------------------------------------------------------------ Where can I find a PHP web host? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/584 ------------------------------------------------------------ Mark Jeftovic Try checking the list at: http://phphosts.easydns.com/ ------------------------------------------------------------ How can I get the output of a perl script in my PHP script? How can I get the results returned from a call to exec()? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/585 ------------------------------------------------------------ Teodor Cimpoesu Just read the docs carefully. exec("/bin/something",$out,$how); http://www.php.net/manual/function.exec.php3 execs something, outputing in $out array (one line per entry), and eventually giving the exit status in $how. If you want the perl script executed via CGI, see virtual(). ------------------------------------------------------------ Do I need to escape characters inside a [] set in a regular expression? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/587 ------------------------------------------------------------ Adam Trachtenberg You don't need to escape "." and "-" inside of [], since it's clear they represent literal "." and "-", not regex metacharacters. ------------------------------------------------------------ Where can I use a hyphen (-) inside a [] set in a regular expression? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/588 ------------------------------------------------------------ Adam Trachtenberg Inside of [] in a regex, if you want a literal "-" it must be at the beginning or end of the characters; otherwise, it specifies a range of characters, as in a-z. ------------------------------------------------------------ How can I exit or break out of a while loop? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/589 ------------------------------------------------------------ Kim Shrier What about "break"? ie while (condition) { break; } ** OTHER RANDOMLY SELECTED PHPKB ENTRIES ** ------------------------------------------------------------ What is the OR operator in PHP? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/411 ------------------------------------------------------------ You can use either || or the keyword 'or'. For more information see: http://www.php.net/manual/language.operators.logical.php3 Be careful though, these different operators have different precedence levels: http://www.php.net/manual/language.operators.precedence.php3 ------------------------------------------------------------ How do I reference a variable that is defined inside a class? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/31 ------------------------------------------------------------ You need to do $object->var. For example: class Foo { var $i; function Foo() { $this->i = new Bar; } } $f = new Foo; echo $f->i; ------------------------------------------------------------ Can I create an image by pasting together other images? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/290 ------------------------------------------------------------ How about something like this, it works and may give you some ideas. It basically takes three images and 'pastes' them together with some text to produce a single button, it also does some calculation to work out the correct size etc. <?php if (!isset($text)){ $text="this is a test"; } $fontsize=11; $angle=0; $fontfile="c:/winnt/fonts/tahomabd.ttf"; $leftbit=imagecreatefromgif("support_image/emptyleft.gif"); $rightbit=imagecreatefromgif("support_image/emptyright.gif"); $middlebit=imagecreatefromgif("support_image/emptymiddle.gif"); $size=imagettfbbox( $fontsize, $angle, $fontfile, ' ' . stripslashes($text) . ' '); $twidth=((int)$size[4]-(int)$size[0]); $htwidth=$twidth/2; if (($twidth)<69){ $twidth=69; } $bwidth=$twidth+11; $height=((int)$size[3]-(int)$size[1]); $target=imagecreate($bwidth,30); imagecopyresized($target,$leftbit ,0,0,0,0,6,30,6 ,30); imagecopyresized($target,$middlebit,6,0,0,0,$bwidth,30,69,30); imagecopyresized($target,$rightbit ,(int)$twidth+6,0,0,0,5,30,5 ,30); $white = ImageColorAllocate($target,255,255,255); $black = ImageColorAllocate($target,0,0,0); imagettftext( $target, $fontsize, $angle, ((int)$bwidth/2)-((int)$htwidth)+2, (int)$height/2+17, $white, $fontfile, stripslashes($text)); Header( "Content-type: image/gif"); imagegif($target); #print $bwidth . "<br>" . "$twidth"; ?> ------------------------------------------------------------ How can I work out the days in a month? When was the 't' option for date() introduced? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/531 ------------------------------------------------------------ From the manual: http://www.php.net/manual/function.date.php3 the option to use is: t - number of days in the given month; i.e. "28" to "31" so your code looks like: $days_this_month = date('t'); // specify a timestamp if you want a different month The 't' option was introduced in version 3.0.10 ------------------------------------------------------------ How can I display a number with exactly 2 decimal places? How can I format a number for printing? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/39 ------------------------------------------------------------ Two decimal places (with thousands separator) is: number_format($num, 2); With no thousands separator try: number_format($num, 2, '.', ''); http://www.php.net/manual/function.number-format.php3

« previous php.kb (#26) next »