<?php echo rtrim("Test "); // Test //Will remove the spaces from the end ?>
Category Archives: PHP
Remove spaces from the beginning of a string – PHP
<?php echo ltrim(" Test"); // Test //Will remove the spaces from the beginning ?>
Command to install PHP – Ubuntu Linux
sudo apt-get install php5
How to decode the data – PHP
<?php $enData =base64_encode("First"); echo base64_decode($enData);//First ?>
How to encode the data – PHP
<?php echo base64_encode("First"); ?>
How to check whether a file exists or not – PHP
<?php if(file_exists($filePath)) echo "Exists" ?>
How to delete a file – PHP
<?php unlink("../".$deleteFilePath) or die("could not delete the file"); ?>
How to terminate the current script – PHP
<?php chmod("../".$image_thumb_path_medium,0777) or die("Could not change permission thumb"); chmod("../".$image_thumb_path_medium,0777) or exit("Could not change permission thumb"); ?>
Modify the permission of a file/directory – PHP
<?php chmod("/your_dir/your_file", 0600); // Read and write for owner, nothing for everybody else chmod("/your_dir/your_file", 0644); // Read and write for owner, read for everybody else chmod("/your_dir/your_file", 0755); // Everything for owner, read and execute for others chmod("/your_dir/your_file", 0750); // Everything for owner, read and execute for owner's group ?>
Remove the first and last item of the array – PHP
<?php $sampleData = array('10', '20', '30.30', '40', '50'); array_shift($sampleData); array_pop($sampleData); print_r($sampleData); // Array ( [0] => 20 [1] => 30.30 [2] => 40 ) ?>