function

Fetching and saving the contents of a remote file

Fetching and saving the contents of a remote file

Submit a query to a search engine and save the results to a local file

1. Create a form that submits a query to a search engine.

2. Script should automatically save the query results to a file. Each query should be saved to separate files.

Figuring out the url of the remote file/search engine that you will submit your query to:

      Subscribe in a reader

A Closer Look: Five MySQL functions that handle query results

A Closer Look: Five MySQL functions that handle query results

Assigning variable names to a MySQL result set

After executing a query to select data from a MySQL table there are several functions you can use to perform operations on the retrieved data.

mysql_result() - fetches the contents of the specified cell

mysql_data_seek() - moves to the specified row of a result set

mysql_fetch_array() - fetches the next row in the result set as an array

mysql_fetch_object() - fetches the next row in the result set as an object

      Subscribe in a reader

The Image Creation Capabilities of PHP

The Image Creation Capabilities of PHP

PHP image functions will allow you to create images dynamically

"The format of images you are able to manipulate depend on the version of GD you install, and any other libraries GD might need to access those image formats. Versions of GD older than gd-1.6 support gif format images, and do not support png, where versions greater than gd-1.6 support png, not gif." -- From the PHP Manual: Image Functions

      Subscribe in a reader

Count the number of MySQL Queries

Count the number of MySQL Queries

How to count the number of MySQL queries used by your script

One way of optimizing your scripts that connect to MySQL databases is to determine how many queries to the database your script makes. If you would like to count the number of queries, you can write a script that will do so. You use this function in place of the regular mysql_query() function.

PHP Code:

<?php

function cnt_mysql_query($sql=FALSE)
{
static $queries = 0;
if (!$sql)
return $queries;

$queries ++;

return mysql_query($sql);
}

$sql= "SELECT 8+9";

      Subscribe in a reader

Password protecting a file using PHP functions

Password protecting a file using PHP functions

How to password protecting a file using FTP functions

There is an alternative to using .htaccess and .htpassword to password protect files.
PHP can mimic the HTTP authentication process by setting the appropriate headers for the username/password dialog box to pop up. The values entered in the box are stored in the $PHP_AUTH_USER, $PHP_AUTH_PW and $PHP_AUTH_TYPE variables.

In order to use FTP functions with your PHP configuration, you should add the --enable-ftp option when installing PHP 4, and --with-ftp when using PHP 3.

      Subscribe in a reader

Creating text files with PHP

Creating text files with PHP

PHP has file handling functions that can create, read or delete files. To to create a text file several functions are used together. The fopen() function, opens a file for writing, the fputs() function
to actually write information to a file, and the fclose() function to close the file when it is no longer
going to be used.

Function fopen(string filename, string mode)
The function expects to be given the name of file, and the reading/writing mode of the file, and returns a file handler.

Note: Modes that can be used to create a new text file are:

      Subscribe in a reader

Transfer Values Between Pages

Transfer Values Between Pages using Javascript

(Written by: geeeet -> Visit Homepage)

With this little piece of code, it's possible to transfer values between pages, just like if you were using a serverside language, like php, jsp or asp.

HTML Code:
// This function extracts the values from the url
function getValues(){
var urlEnd = document.URL.indexOf('?');
var values = new Array();
var names;

if (urlEnd != -1){
var params = document.URL.substring(urlEnd+1, document.URL.length).split('&');

      Subscribe in a reader

Uploading Files with PHP

You can use a browser to upload files with PHP. The files can be either text and binary files. PHP has several file manipulation functions, that allow you to control what you do with a file once it has been uploaded, how large the file to be uploaded should be, where it should go after being uploaded etc.

To upload files, create a file upload form:

Example:

Send this file:

      Subscribe in a reader

Sending email with PHP's mail function

Sending email

The mail function in PHP is of course used to send mail to a specified email address. Multiple recipients can be specified by putting a comma between each email address in the to argument of the mail function.

usage:
mail(string to, string subject, string message, string [additional_headers]);

The additional_headers argument is used to set extra headers such as 'From', 'Reply-To', 'X-Mailer' etc. Multiple extra headers are separated with a newline (n).

Example:
mail("someone@somewhere.com", "A Subject", "Some text, in the body of the email.");

      Subscribe in a reader
Syndicate content