PHP: Check If Two Strings Are Similar

In php, to check the similarity between to strings (text) use the similar_text for example:

Here’s a PHP function that’ll help you check if two strings (texts) are similar. If the strings are 50% similar then the function will output “Duplicate Entries”.

 0) {
	if (count($result)>(count($array1)/2)){
		echo "Duplicate Entries";
	};

};
}

issimilar ( "Hello World Foo Bar Baz", "Hello Foo Bar Baz");

?>

Regular Expressions: Remove Links Hashes & Mentions from Tweet

Use this regular expresion to remove URLs (http://…) hashes (#ahash) and mentions (@amention) from Tweets or any other block of text for that matter.

For PHP code use:

/(@|#|http\:\/\/)([a-zA-z0-9\.\/])+/

 

For JavaScript:

^(@|#|http\:\/\/)([a-zA-z0-9\.\/])+$

 

 

PHP: Get Folder Size & File Count

Here is a little PHP code you can use to get the size and file count of an entire directory including sub-directories

$filename){
  if($filename!=".." && $filename!="."){
   if(is_dir($dir."/".$filename)){
    $new_foldersize = foldersize($dir."/".$filename);
    $count_size = $count_size + $new_foldersize[0];
    $count = $count + $new_foldersize[1];
   }else if(is_file($dir."/".$filename)){
    $count_size = $count_size + filesize($dir."/".$filename);
    $count++;
   }
  }
  
 }
 
 return array($count_size,$count);
}

$sample = foldersize("SAMPLE_DIRECTORY");

echo "Folder Size : " . $sample[0] . " Bytes 
" ; echo "File Count : " . $sample[1] . " Files " ; ?>

Changing “upload_max_filesize” in php.ini on GoDaddy Shared Hosting

Changing upload_max_filesize on GoDaddy

Are you running your website on a GoDaddy shared hosting plan? Are trying to upload a file using a PHP script and you can’t get it to upload files larger than 8 MB? Do you want to change the maximum allowed file size for uploads? If this is the case, I have a solution for you. Place the following code in your php.ini file in the script directory (If there is no php.ini file, create one.)

 

rg_emulation = off
allow_url_fopen = on
memory_limit = 25000M
post_max_size = 9000M
file_uploads = On
max_execution_time = 3000000000
max_input_time = 30000000000
upload_max_filesize = 9000M

 

Please note that it may take a few hours for the changes to take affect.

Let me know if these settings worked for you.

Clear Browser Cache Using HTML or PHP

To clear the browser cached page or to force the browser to re-download the content of a page, you can place the following HTML code in the header tags (<head>) of the page. This code will ask the broswer to ignore any saved copies of the page, and to re-download page content.

HTML Code:





 

If you prefer working with PHP, you can do the exact same using this PHP code:

PHP Code:

header ("Expires: ".gmdate("D, d M Y H:i:s", time())." GMT");  
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");  
header ("Cache-Control: no-cache, must-revalidate");  
header ("Pragma: no-cache");

Open PHP as a Text File Using .htacess

Place this code in the .htaccess file to disable processing of PHP files in a folder. This will remove the PHP handlers in Apache forcing the browser to load the PHP file as a text file. You can use this to secure folders where upload is allowed to prevent executing uploaded PHP files.

RemoveHandler .php .phtml .php3
RemoveType .php .phtml .php3

Commenting HTML, CSS, PHP, Javascript, SQL & ASP

Use the tags below to enter comments or notes in your HTML, CSS, PHP, JavaScript or ASP code:


Language Single/Multi-Line Start with End with Example

HTML

Single & Multi-Line

<!–

–>

<!– This is an HTML Comment –>

PHP

Single Line

//

// This is a PHP Comment

PHP

Mutli-Line

/*

*/

/* This is

a PHP Comment */

JavaScript

Single Line

//

// This a JScript Comment

JavaScript

Mutli-Line

/*

*/

/* This is

a JavaScript Comment */

CSS

Single & Multi-Line

/*

*/

/*This is a CSS comment*/

ASP

Single & Multi-Line

‘ This is an ASP Comment

SQL

Single & Multi-Line

{

}

{ This is an SQL Comment }

SQL

Single

— (Two dashes)

— This is an SQL Comment

PHP: Country Name from IP Address

Here’s a PHP script that demonstrates an easy way to get a country name or code from IP address using pure PHP.

Included in the file:

GeoIP.dat: a binary databases of countries and IPs maintained by MaxMind.com. The database is updated monthly and has a 99.5% accuracy rate. You can always get the latest version here.

geoip.inc & sample.php: The PHP script.

Download: php-ip-to-country.zip ~ 627KB