Stripping Characters from Strings with PHP

This is a simple example of stripping chararcters from a string using PHP.
See comments in code below for results...

<?
$string = "1234567890";
$string = substr($string, 6); //strips off 123456
echo $string; //7890
 
$string = "123456";
$string = substr($string, 0, 1);  //get first character
echo $string; //1
?>


Highlight Table Row on Mouse Over

Simple Javascript to highlight table rows on mouse over...
 

<script type="text/javascript">

function hiLiteRows(){
var x = document.getElementsByTagName('tr');
for (var i=0;i<x.length;i++)
{
x[i].onmouseover = function () {this.origColor=this.style.backgroundColor;
this.style.backgroundColor='#D8E5F2';
}
x[i].onmouseout = function () {this.style.backgroundColor=this.origColor;}
}
}

window.onload=hiLiteRows;

</script>


Comma Seperated List

Easy way to create a comma seperated list, pulled from a mysql database table-

<?
$query = mysql_query("SELECT item FROM table WHERE color = 'red'");

$system_array = array() ;
$i = 0 ;
while ( $row = mysql_fetch_assoc( $query ) )
{
   $system_array[ $i ] = $row[ 'item' ] ;
   $i++ ;
}
$item_list =  implode( ', ', $system_array ) ;
echo $item_list;
?>


Date Formatting

Some example code on date formatting...

<?
$thirtyDays = mktime(date("H"), date("i"), date("s"), date("m"), date("d")+30, date("y"));
$sixtyDays = mktime(date("H"), date("i"), date("s"), date("m"), date("d")+60, date("y"));

//Display Current Date, 30 Days from Date, 60 Days from Date
echo "Today: ". date('Y-m-d H:i:s') . "<br />";
echo "30 Days: ". date('Y-m-d H:i:s',$thirtyDays) . "<br />";
echo "60 Days: ". date('Y-m-d H:i:s',$sixtyDays) . "<br />";
?>
<br />
<?
//Current Date Formatted
echo date("F j, Y, g:i a") . "<br />";

//30 Days from Current Date, formatted
echo date("F j, Y, g:i a", $thirtyDays);
?>