Home  |  Linux  | Mysql  | PHP  | XML
From:Nathan Wallace Date:Fri Sep 17 03:09:49 1999
Subject:PHP Knowledge Base Update -- September 16th, 1999
I wrote a quick installation guide today for setting up PHP command line 
scripting.  It's available with my other instruction sets at:

    http://www.e-gineer.com/e-gineer/instructions/index.phtml

I've also just published a new article on e-gineer:

    Should I Open Source?
    http://articles.e-gineer.com/should-i-open-source.phtml

Cheers,

Nathan


------------------------------------------------------------
How do I append a new item to an array?
How can I add new items to the end of an array?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/624
------------------------------------------------------------
Richard Lynch

If you have an array in PHP:

    $a = array('a', 'b', 'c');

you can add new items to the end like this:

    $a[] = 'd';
    $a[] = 'e';


------------------------------------------------------------
How can I log suppressed error messages to a file?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/626
------------------------------------------------------------
Richard Lynch

I'm guessing that:

    http://php.net/manual/feature-error-handling.php3

will have something in it, since if you don't suppress the error 
message, something does get dumped to the screen, no?

If all else fails, you could write your own error message for this once
case, perhaps even including the name of the script ($PHP_SELF) and the
line number (__LINE__) and the name of the database and other connection
info (not password, of course).

You may also wish to read:

    http://www.php.net/manual/function.error-log.php3

which will avoid the problem of, say, your code not being able to open 
the log file to log the error message.


------------------------------------------------------------
How can I select all rows that have a date column more than one week old?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/627
------------------------------------------------------------
Chris Cosentino

Well, if you are using MySQL and you have a field with a DATE type that 
you want to run a query against, you can do something like this:

    $query = mysql_query("select * from news where
                          (to_days(now())-to_days(news.date))>='7'");
    while ($myrow = mysql_fetch_array($query)) {
        #Do stuff to $myrow...
    }


------------------------------------------------------------
How can I sort LDAP entries?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/628
------------------------------------------------------------
Alex Dyas

Assuming you've read all the records into an array you can use the usort
function to do it.  Something like this:

<code>

// used to sort entries
function EntryCompare($a,$b)
{
        $sortfield = "userid";
        if($a[$sortfield]==$b[$sortfield])
        {
                return 0;
        }

        if($a[$sortfield]>$b[$sortfield])
        {
                return 1;
        }
        else
        {
                return -1;
        }
}

// Sort the entries
usort($entries,EntryCompare);

</code>

$entries is the array with all the ldap records, and $sortfield is the 
field on which you want to sort.


------------------------------------------------------------
Can you give me quick instructions for installing PHP4 on Red Hat 6?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/629
------------------------------------------------------------
Rasmus Lerdorf

Apache-1.3.9: ./configure --with-layout=RedHat --enable-module=so
              make
              make install

PHP-4.x: ./buildconf
         ./configure --with-apxs=/usr/sbin/apxs
         make
         make install

Then edit /etc/httpd/conf/httpd.conf

and Make sure you have an AddType line like this:

  AddType application/x-httpd-php .php

(The extension you use is arbitrary)

Then do: apachectl start


------------------------------------------------------------
How can I run PHP code that is in a string?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/630
------------------------------------------------------------
Lars Torben Wilson

Check out the eval function:

    eval('my php code');

    http://www.php.net/manual/function.eval.php3


** OTHER RANDOMLY SELECTED PHPKB ENTRIES **


------------------------------------------------------------
Can I use references to variables in PHP3?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/22
------------------------------------------------------------

No, this isn't available in PHP3. It is promised for PHP4. 

Actually, PHP3 supports a limited form, in that function arguments may 
be passed by reference. Otherwise, you'll have to wait.



------------------------------------------------------------
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



------------------------------------------------------------
How can I import a flat file into MySQL?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/181
------------------------------------------------------------

It sort of depends on the format of the flatfile.

If the file was created with SELECT INTO OUTFILE, it can
be reimported with LOAD DATA INFILE.

Otherwise you'll probably want to slurp up the file
with the file() operator, split into fields with 
explode() or split() -- after trimming newline characters
off the end with chop().

Then assemble INSERT commands and pass them to mysql_query().

I'm not certain if LOAD DATA INFILE works within
a mysql_query() call, although I'd imagine so.


------------------------------------------------------------
What is the difference between = and ==?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/171
------------------------------------------------------------

The assignment operator (=) is used to assign a value to a variable. 
For example:

    $a = 23;
    // $a now holds the number 23

The equality operator (==) is used to compare two values for equality. 
For example:

    if ($a == 23) {
        // $a is equal to 23
    }
    else {
        // $a is not equal to 23
    }


------------------------------------------------------------
Where can I get PHP4?
When can I get PHP4?
What is Zend?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/100
------------------------------------------------------------

PHP4 is the next version of PHP, with the language parser
replaced with a newer, faster engine called Zend.  Zend isn't a
stand alone language like PHP (i.e. you don't just run "Zend"
on your server, you run PHP4, which has "Zend" under the hood).

PHP4 is like a car, with the old motor removed, and a better engine
(Zend) put in in its place. :)




Navigate in group php.kb at sever news.php.net
Previous Next




  
© No Copyright
You are free to use Anything
Site Maintained by PHP Developer
Powered By PHP Consultants