Php
PHP read a files into an array
function read_file_data_to_array($filepath, $load_keys=false, $filetype) {
if($filetype=="csv") $separator=",";
else if($filetype=="tsv") $separator=" ";
$array = array();
if (!file_exists($filepath)){ return $array; }
$content = file($filepath);
for ($x=0; $x < count($content); $x++){
if (trim($content[$x]) != ''){
$line = explode("$separator", trim($content[$x]));
if ..
Writing some text on jpeg image using php
header('Content-type: image/jpeg');
$text = "TechBluff!"; # sample text to be used in a jpeg picture.
$font = 'ambient.ttf'; # font style
$image = imagecreatefromjpeg('watermark.jpg'); # sample image where the text to be used.
$text_col= imagecolorallocate($image, 255, 255, ..
Include HTML file in php
Here it is the simple php code that helps you to include your html webpage to php file.
HTML file or code to be included in php
<li><a href='home.php'>home</a></li>
<li><a href='contactus.php'>Contact</a></li>
<li><a href='bluff.php'>Bluff</a></li>
<li><a href='programming.php'>Programming</a></li>
php code to include a html file
<?php include ("menus.html"); ?>
Consider you have html file called menus.html ..
Load webpage faster using encoded image
Load webpage faster using encoded image in php, this helps you to load your page faster.
function encode_image($filename){
$contents = file_get_contents($filename);
$base64 = base64_encode($contents);
$imagetype = exif_imagetype($filename);
$mime = image_type_to_mime_type($imagetype);
return "data:$mime;base64,$base64";
}
How ..
Php - split tamil characters
How to Split tamil character string in php
Tamil characters are stored in database or fetched in unicode format. Characters can be splitted using preg_match_all function in php.
# preg_match_all('/pLpM*|./u', $str, $results)
where,
pL - Match Unicode letter
pM - Match Unicode mark
$str - Input string to be seperated
$result - Result of input passed. ..
How to use goto operator in php
Features of php GOTO operator
1) The goto operator can be used to jump to another location in a program.
2) The instruction is like goto followed by any label name.
3) The target location is specified by the label name followed by a colon.
4) The target label must be within the same ..
Php - serialize unserialize an array
how to serialize and unserialize an array in php?
As arrays are complex data types, you cannot see their contents directly. If you try printing out the value of an array, you will see PHP just outputs \'Array\', which means that passing the value of an array through a link requires ..
How to split tamil characters
Split the tamil characters from tamil word using php. The preg_match_all() function is used to split tamil words. let assign,
$string1="தமிழ்";
preg_match_all('/pLpM*|./u', $string1, $result);
Now print the $result array , you will get the splited tamil characters.
print_r($result);
Output:
Array
(
[0] => Array
(
[0] => த
[1] => மி
[2] ..
Split numbers from string
Split Numbers From String Using Php
To split numbers present at last of a string and increment the number by 1 using php
$vname="words9999";
echo "Initial value==".$vname;
$i = 1;
$strln=strlen($vname);
for($j=0;$j<=$strln;$j++)
{
$nm=substr($vname,-$j);
if (!preg_match('/[^0-9]/', $nm))
{
$vnameapp=$nm;
}
}
$vnam=explode($vnameapp,$vname);
$vnameapp++;
..
Php sorting an array
Example Input:
Array ( [a1] => 14959.14 [a2] => 10747.94 [a3] => 19531.23 [a4] => 8915.83 [a5] => 2646.25 [a6] => 28379.74 [a7] => 727.25 )
Syntax:
# array_multisort(array1,sorting order,sorting type,array2,array3...)
Where,
array1 = Specifies an array(Required)
sorting Order = Specifies the sorting order(Optional).
Possible values:
SORT_ASC Default. Sort in ..
Creating graphical image using php
The below code can be used to create graphical image, it is a simple code code which is used used to create sample images
<?php
$pic = imagecreatetruecolor(400,400); // for create canvas with 400 * 400 size
$bluecol = 0;
for ($i = -10; $i < 410; $i ..
Search fo url in a file
Check wheather a url exists in a files or not.
function urlOK($url)
{
$url_data = parse_url ($url);
if (!$url_data) return FALSE;
$errno="";
$errstr="";
$fp=0;
$fp=fsockopen($url_data['host'],80,$errno,$errstr,30);
if($fp===0) return FALSE;
$path ='';
if (isset( $url_data['path'])) $path .= $url_data['path'];
if (isset( $url_data['query'])) $path .= '?' .$url_data['query'];
$out="GET /$path HTTP/1.1rn";
..
Php global variable
PHP global variable access inside the class
<?php
define('MYCONST', 'varname');
$varname = array("This is varname", "and array?");
class Myclass {
public $classvar;
function Myclass() {
$this->classvar =& $GLOBALS[MYCONST];
}
function printvar() {
echo $this->classvar[0];
echo $this->classvar[1];
}
};
$myobj = new Myclass;
$myobj->printvar();
?>
..
Check url
How to search if URL exists in a particular link?
This method is the easiest way to check whether a proper url is having in a particular link. Many of them click the wrong link and choose in complex way.Using the following trick you can do it in a useful way.
..
Simple animated gif image
How to create animated gif using php
if(isset($_POST['speed']))
{
header('Content-type: image/gif');
if(isset($_POST['download'])){
header('Content-Disposition: attachment; filename="animated.gif"');
}
include('class.php');
function frame($image){
ob_start();
imagegif($image);
global $frames, $framed;
$frames[]=ob_get_contents();
$framed[]=$_POST['speed'];
ob_end_clean();
}
foreach ($_FILES["images"]["error"] as $key => $error)
{
if ($error == UPLOAD_ERR_OK)
{
$tmp_name = $_FILES["images"]["tmp_name"][$key];
$im = imagecreatefromstring(file_get_contents($tmp_name));
$resized = imagecreatetruecolor($_POST['width'],$_POST['height']);
imagecopyresized($resized, ..