Home  |  Linux  | Mysql  | PHP  | XML
From:Nathan Wallace Date:Sun Aug 15 10:06:55 1999
Subject:PHP Knowledge Base Update -- August 14th, 1999
I start travelling tomorrow so this will be the last PHPKB Update for at
least 2 weeks.

Cheers,

Nathan


------------------------------------------------------------
How can I replace all <table ...> tags?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/600
------------------------------------------------------------
Gianluca Baldo

Try this:

    $new_table = eregi_replace("<table[^>.]*>",$replace,$table);


------------------------------------------------------------
How can I get the number of rows in a database table?
What's the fastest way to return the number of rows in a table?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/601
------------------------------------------------------------
Adam Whitehead

To get the number of rows in a table you should use the COUNT(*) feature
in SQL.

Here is an example for MySQL:

    $res = mysql_db_query($db,"select count(*) from TABLE_NAME");
    $row_count = mysql_result($res,0,"count(*)");


------------------------------------------------------------
How unique are values generated by MD5?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/603
------------------------------------------------------------
Russ Steffen

MD5 is a cryptographically strong hash function. Sure, it is technically
possible for two of your unique numbers to generate the same hash. It is
however, highly unprobable. In fact, if you started a brute force search
now for two strings of similar length that hash to same value, you are
not likely to find them until sometime after the Sun runs out of fuel.


------------------------------------------------------------
How can I set the User-Agent string for the web robot I'm writing?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/604
------------------------------------------------------------
se@lakenet.no

If you open a socket to retrive the pages, you just output:

    "User-Agent: whatever\n"

as one of the request headers.

I would use something like

    "User-Agent: bot_name/bot_version (bot_purpose; your@email)\n"

(and try to make the robot honor "robots.txt" and other nice things ;)

if you use fopen(" http://... the User-Agent is set somewhere near line
588 in fopen-wrappers.c...


------------------------------------------------------------
How can I get the current day of the year as a number (eg: 358)?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/605
------------------------------------------------------------
se@lakenet.no

look at the function date():

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

z - day of the year; i.e. "0" to "365", so:

    $day_number=date("z");

This returns January 1 as being 0.  If you want the day numbers to be
the usual 1-365 then you should use:

    $day_number=date("z")+1;


------------------------------------------------------------
Can I return other file formats (like Word, Excel, etc) using PHP?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/606
------------------------------------------------------------
Manuel Lemos

As long as you know how to output data in those formats that is easy. 
All you need to do is to set the Content-Type:  header to the respective
MIME type of the output format. For instance for the Excel format you
would do:

    Header("Content-Type: application/vnd.ms-excel");

If you want to set the file name of outputted data you may want to do as
follows:

    Header("Content-Location: ".$file_name);
    Header("Content-Disposition: filename=".$file_name);


** OTHER RANDOMLY SELECTED PHPKB ENTRIES **


------------------------------------------------------------
Will calling getimagesize() for every image on a page slow things down?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/453
------------------------------------------------------------

getimagesize() will slow things down a bit if you think about it.  It
has to open up each of those 30 images and read enough of them to figure
out the size of the image each contains.


------------------------------------------------------------
What's the easiest way to remove characters from the end of a string?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/514
------------------------------------------------------------

See the function substr():

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

For example:

    $rest = substr("abcdef", 1, -1); // returns "bcde"

so to remove characters from the end of a string you can use:

    $rest = substr("abcdef", 0, -2); // returns "abcd"


------------------------------------------------------------
Can I use Javascript to encrypt passwords entered in HTML forms?
How can I send a users password from a HTML form back to the server encrypted?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/439
------------------------------------------------------------

The most common technique to do so is to use Javascript to encode the
password field right before submitting the form.

I have developed a PHP class that generates forms with the necessary
Javascript code to do so. The the page located at the URL below you may
find the code for that class as well an example to do what you need.

The class uses an hidden field to store the encoded version of the
password and clears the password field after validating the form.

In this case the md5 algorithm is used.  This assumes that you will be
able to check your password on the server side with the correct password
also encoded as md5.  You may use other encoding algorithms if you can
provide a Javascript to implement them.

Note that the ability to encode passwords this way before submitting a
form relies on a Javascript enable browser.  If the browser does not
support Javascript, it will still send the password in clear text.

http://phpclasses.upperdesign.com/browse.html?package=1


------------------------------------------------------------
Why can't I see the contents of my cookie in a function?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/396
------------------------------------------------------------

PHP treats every variable as local to the function unless you specify it
as global.  Thus, you cannot access $HTTP_COOKIE_VARS in a function
unless you declare it as global inside that function.

This should work:

    function ReadCookie($name) {
        global $HTTP_COOKIE_VARS;
        return $HTTP_COOKIE_VARS[$name];
    }

Similarly the cookie is not accessable by name unless you declare it as
global.  In this case what we actually want is the variable that holds
the cookie (the one called $name) to be global, so we have to globalize
the variable variable...

    function ReadCookie($name) {
        global $$name
        return $$name;
    }


------------------------------------------------------------
How can I create a column in MySQL that auto increments?
How can I insert data into MySQL with an automatic unique ID?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/255
------------------------------------------------------------

In MySQL you just create a column of type integer and give it the
AUTO_INCREMENT attribute.

    create table foo (
        bar integer auto_increment );

In MySQL, the AUTO_INCREMENT attribute may be specified for any of the
integer column types (TINYINT, SMALLINT, MEDIUMINT, INT (or its synonym,
INTEGER)), and BIGINT), depending on the range you need. AUTO_INCREMENT
values begin at 1 and increase by 1 for each row.  When you insert a
NULL into such a column, MySQL inserts a value one greater than the
maximum value currently in the column.

AUTO_INCREMENT columns must be declared NOT NULL, and you must declare
them as a PRIMARY KEY or as a UNIQUE index.  In addition, since all
valid AUTO_INCREMENT values are greater than 0, you may want to declare
the column UNSIGNED to extend the range of your sequence.

The following two statements are equivalent.  Each creates a table with
an AUTO_INCREMENT column:

CREATE TABLE my_tbl (i INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY)
CREATE TABLE my (i INT UNSIGNED NOT NULL AUTO_INCREMENT, UNIQUE (i))

http://www.mysql.com/Manual_chapter/manual_Reference.html#CREATE_TABLE



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