How to delete file in PHP


To delete the file from server we use unlink()


Example:
<?php
$filename = "testfile.txt";
unlink($filename);
?>

Example:
<?php
$file = fopen('test.txt', 'a');
fwrite($file, 'how to delete file');
fclose($file);
unlink('test.txt');//delete test.txt file.
?>
Advertisements

Difference between strstr and stristr in php


strstr() and stristr both are used to find the first occurence of the string.

stristr( ) is case insensitive and strstr( ) is case sensitive.


string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] )

haystack
The input string.
needle
If needle is not a string, it is converted to an integer and applied as the ordinal value of a character.
before_needle
If TRUE, strstr() returns the part of the haystack before the first occurrence of the needle (excluding the needle). By default it is FALSE.

strstr() – Find first occurrence of a string Continue reading

.htaccess and its features


HTACCESS means HyperText Access.

.htaccess files should be used in a case where the content providers need to make configuration changes to the server on a per-directory basis, but do not have root access on the server system.

Some main features of .htaccess file are:

  • ability to password protect folders
  • ban / allow users using IP addresses
  • stop directory listings
  • enable complete error reporting
  • redirect users to another page or directory automatically
  • create and use custom error pages
  • Adding MIME types
  • Setting server timezone
  • Enable SSI (Server Side Includes) with .htaccess
  • Ensuring media files are downloaded instead of played
  • Preventing requests with invalid characters
  • change the way files with certain extensions are utilized
  • use a different file as the index file by specifying the file extension or specific file.

Difference between mysql_connect() and mysql_pconnect()


Shruti's Space

mysql_connect() and mysql_pconnect() both are working for database connection but with little difference. In mysql_pconnect(), ‘p’ stands for persistance connection.

When we are using mysql_connect() function, every time it is opening and closing the database connection, depending on the request .

But in case of mysql_pconnect() function,
First, when connecting, the function would try to find a (persistent) connection that’s already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.
Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the connection will remain open for future use (mysql_close() will not close connection established by mysql_pconnect()).

mysql_pconncet() is useful when you have a lot of traffice on your site. At that time for every request it will not open a connection but will take it…

View original post 33 more words

Types of Errors in PHP


Basically there are four types of errors in PHP, which are as follows:

  1. Parse Error (Syntax Error)
  2. Fatal Error
  3. Warning Error
  4. Notice Error

1. Parse Errors (syntax errors)

The parse error occurs if there is a syntax mistake in the script; the output is Parse errors. A parse error stops the execution of the script. There are many reasons for the occurrence of parse errors in PHP. The common reasons for parse errors are as follows:

Common reason of syntax errors are:

  • Unclosed quotes
  • Missing or Extra parentheses
  • Unclosed braces
  • Missing semicolon

Continue reading