PHP function to remove whitespaces from a string
Usage :
$spaceRemovedString = removeWhiteSpaces($stringWithSpace);
Function :
function removeWhiteSpaces($spaceStr) { $newStr = preg_replace('/\s+/', '', $spaceStr); return $newStr; }
Archive for the ‘ PHP ’ Category
Usage :
$spaceRemovedString = removeWhiteSpaces($stringWithSpace);
Function :
function removeWhiteSpaces($spaceStr) { $newStr = preg_replace('/\s+/', '', $spaceStr); return $newStr; }
Sometimes , we need to write some logging information to a text file in php. The following function takes filename and message as the parameter and logs whatever you pass to the file with date and time.
function logToFile($fileName, $logMessage)
{
$logDirectory = “/path/to/log/dir”;
$fileHandler = fopen($logDir . '/' . $fileName , "a");
$logText = date("Y-m-d h:i:s") . "---" . $logMessage . "\r\n";
fwrite($fileHandler, $logText);
fclose($fileHandler);
}
The information provided here are correct to my knowledge and my experience. Please use all the advices, scripts and configurations at your own risk. I cannot be held liable for any damage or loss at your side by use of these articles, scripts or tutorials in any way.
M | T | W | T | F | S | S |
---|---|---|---|---|---|---|
« Jan | ||||||
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 |