PHP Category

preg_match + $_server

In: Apache Useful Links, PHP

<?php
$geturl=$_SERVER['HTTP_HOST'];
if(preg_match(”/xxx.com/i”, $geturl))
{
$geturl=preg_replace(’#aaa.com#is’,”,$geturl);
?>
<meta http-equiv=’refresh’ content=’0; url=<?php echo $geturl;?>’>
< ?php
exit;
}
?>

Getting The Day of a Date YYYY-MM-dd

In: PHP

$date = ‘2008-11-13′;
echo date(’l', strtotime($date));
*this will echo Thursday
/////////////////////////
$date = ‘2008-11-13′;
echo date(’D', strtotime($date));
*this will echo Thu

array looping

In: PHP

<?php
$thearray = array(”green”, “red”, “yellow”);
foreach($thearray as $key => $value) {
echo $key . ” ” . $value . “<br>”;
}
?>

List all Files and folders in a Directory

In: PHP

<?php
// declare the folder
$ourDir = “/home/public_html/folderName”;
// prepare to read directory contents
$ourDirList = @opendir($ourDir);
// loop through the items
while ($ourItem = readdir($ourDirList))
{
   // check if it is a directory
   if (is_dir($ourItem))
   {
      echo “directory: $ourItem <br />”;
   }
   // check to see if it is a file
   if (is_file($ourItem))
   {
      echo “file: $ourItem <br />”;
   }
}
closedir($ourDirList);
?>
 
source: http://www.aspvphp.com/Code/Text_Files/List_all_Files_and_folders_in_a_Directory.shtml

preg_match + preg_replace

In: Regular Expression, function

$to_match=$_SERVER['REQUEST_URI'];
if (preg_match(”/some_words/i”, $to_match))
{
$to_match=preg_replace(’#some_words/#is’,'replace_with_this’,$to_match);
}