Monday, July 02, 2012

Business Opportunities for PHP in the Wireless Market - O'Reilly Media

Business Opportunities for PHP in the Wireless Market - O'Reilly Media

Friday, August 31, 2007

KISS (Keep It Simple and Small/Stupid)

Kiss is a feature in software engineering which lot of us talk and lot of us try to follow too.

I was just trying to write a function which could remove a specified character from the begining of a string and I came up with two functions. The first one spans 20 lines and it uses a preg_split(), array_pop(), implode(), strlen() and 2 times array_reverse() and a for loop and an if else block. With all these you can expect the complexity of the function.

But the second one takes a single while and substr() function. Isnt it greate that a human mind thinks in two entire directions within a span of 1 hr. I think it is just the mood that we are in decides the way we program.

Here are the functions for your reference.


function format_int($val, $pop_what)
{
$val_len = strlen($val);
$tmp_val = $val; //performing the logic on a tmp vlue as just in case if the real value is needed
$tmp_val = preg_split('//', $tmp_val, -1, PREG_SPLIT_NO_EMPTY); //converting string into array
for($i = 0; $i < $val_len; $i++)
{
if(
$tmp_val[0] == $pop_what)
{
$tmp_val = array_reverse($tmp_val);
array_pop($tmp_val);
$tmp_val = array_reverse($tmp_val);
}
else
{
break;
}
}

return
implode("",$tmp_val);
}

function
format_int_smart($val, $pop_what)
{
while(
$val[0] == $pop_what )
{
$val = substr( $val, 1);
}
return
$val;
}


Usage:
format_int("00010","0"); //return 10
format_int_smart("00010","0"); //returns 10

Sunday, January 21, 2007

Installation Steps for PHP as apache2 module (not CGI):
1. Download Apache2 and install it anywhere
2. Download PHP 5.2.0 and unzip it in C:\php
3. you have to tell apache2 where to load the module!

The module for apche 2.0:
php5apache2.dll

or apache 2.2:
LoadModule php5_module "c:/php/php5apache2_2.dll"

and the location of the php.ini directory with the extension where to
enable PHP:
PHPIniDir "C:/php"
AddType application/x-httpd-php .php .html
AddType application/x-httpd-php-source .phps .htmls

modify the php.ini in it's configuration:
extension_dir = "c:\php\ext"

check all these steps, and everything should work fine!

Tags: PHP Apache

Thursday, January 18, 2007

Tips on PHP-MSSQL stored procedures

Tip -1

While using stored procedures on SQL EXPRESS (and perhaps on SQL Server),
you have to specify the column names in SELECT, instead of asterisk (*).
Or else you will get some big Unicode error when you run them in php.

That is, instead of "select * from table",
use "select col1, col2 from table".

Tip - 2
One more important thing, Before using mssql_execute, you MUST AND SHOULD
use mssql_init. mssql_init will generate the MS Sql statement resource,
which will be taken as input by mssql_execute. Here is an example,

<?php
if($conn = mssql_connect('localhost\SQLEXPRESS', 'krishna', 'srikanth'))
echo
'Connected to SQLEXPRESS';

if(
mssql_select_db("Northwind",$conn)) echo 'Selected DB: Northwind<BR>';

$sql_statement = mssql_init("[Ten Most Expensive Products]", $conn);
$result=mssql_execute($sql_statement);

while (
$row = mssql_fetch_assoc($result))
print_r($row);
?>
Thanks to Manda Krishna Srikanth for the tips.
Tag: PHP

Monday, November 27, 2006

How to Know whether Email Sent or Not Using PHP

I was wondering since a long time on how to know whether email sent via PHP's mial() function reached or not. You can do it using error_log() function. Following is a syntax

mail
('to', 'subject', 'message', 'headers') or error_log("Email didn't make it to receipient (insert email address variable here)", 1 , "email_address@to_send_to");

The 2nd argument "1" tells error_log to send the error to the email address provided in the next argument "email_address@to_send_to"

Just for your reference following is a way to validate an email address using regular expressions

function is_valid_email($email)
{
if(
preg_match("/[a-zA-Z0-9_-.+]+@[a-zA-Z0-9-]+.[a-zA-Z]+/", $email) > 0) {
return
true;
}
else {
return
false;
}
}


Tag: PHP PHP MAIL

Thursday, November 16, 2006

Problems Reading PHP Arrays Using each()

When you read PHP arrays using each(); the array cursor will be left on the next element of the array, or past the last element if it hits the end of the array. You have to use reset() if you want to traverse the array again.

Tags: PHP PHP Arrays

Thursday, September 21, 2006

Country list with ISA/ISB Codes

This function will take in a country ISA/ISB code and translate it into full country name. It includes a downloadable SQL file (below)

Link to the downloadable SQL file :http://www.phptricks.com/get_file.php?file_name=country_list.zip&t=2

<?php

//This function takes in a country code "US/GB/.." and returns
//Full country name
//This uses a database to get the name

function get_name($code) {
$reterieve_country = @mysql_fetch_array(@mysql_query("SELECT * FROM countrylist WHERE `lsa`= '$code' OR `lsb`= '$code'"));
if($reterieve_country[1] == NULL){
$country_name = 'Other';
} else {
$country_name = $reterieve_country[1];
}
}
?>

Page numbering from MYSQL data

This will number your pages with the Previous 1 2 3 4 Next sequence.

<?php

//Start out by writing your query(general)
$get_items = "SELECT * FROM `items`";

//How many items to display per page?
$display_limit = '10';

//We need to see how many items are there in the first place
$items_count = @mysql_num_rows(@mysql_query($get_items));

//Are we getting the page count from url or making a new one?
if(isset($_GET['page_count'])) {
$page_count = $_GET['page_count'];
} else {
if($items_count > $display) {
$page_count = ceil ($items_count/$display_limit);
} else {
$page_count = 1;
}
}

//Where are we going to start from?
if(isset($_GET['start'])){
$start = $_GET['start'];
} else {
$start = 0;
}

//Now make the final query (the one we actually using)
$get_items_query = @mysql_query($get_items . " LIMIT $start,$display_limit");

//To display the numbering anywhere under the page use this code//
if($items_count > $display_limit){
$current_page = ($start/$display_limit)+1;
//Do we need to print previous?
if($current_page != 1) {
echo '<a href="index.php?&start=' . ($start-$display_limit) . '&page_count=' . $page_count . '">Previous</a>';
}
//Print out the numbers
for ($i = 1; $i <= $page_count ; $i++) {
if($i != $current_page){
echo ' [<a href="index.php?&start=' . (($display_limit * ($i - 1))) . '&page_count=' . $page_count .'">' . $i . '</a>] ';
} else {
echo '<font color="gray"> [' . $i . '] </font>';
}
}
//Print out Next
if($current_page != $page_count){
echo '<a href="index.php?&start=' . ($start+$display_limit) . '&page_count=' . $page_count . '">Next</a>';
}
}

/* To display the items, you use whatever you want, for our case simply print every item */
while($each_item = @mysql_fetch_array($get_items_query)){
echo $each_item['item_title'];
}
?>

Checking for a user country via Database

This function (which includes database-download from link below), will be able to check for the user's country.

Link for database(zip file): http://www.phptricks.com/get_file.php?file_name=phpskills.com.zip&t=2

<?php
//Function to check for user country
function check_country($ip){
$ip = sprintf("%u", ip2long($ip));
$country = 'other';

$check_country = @mysql_query("SELECT `country`,`a2`,`a3`,`number` FROM `country_ip_list` WHERE `ipfrom` <= '$ip' and `ipto` >= '$ip' LIMIT 0, 1");

if($get_country = @mysql_fetch_row($check_country)){
$country = $get_country[0];
}
return $country;
}

//Sample implementation
$user_country = check_country($_SERVER['REMOTE_ADDR']);
echo "You are from: $user_country";
?>

Whois query checker

This function will output the domain name whois from the whois database.

<l?php
//Whois Checker
function whois($domain,$ext){
$server="whois.networksolutions.com";
if(($sc = fsockopen($server,43))==false){
if(($sc = fsockopen($server,43))==false){
return false;
}
}
if($ext=="com"||$ext=="net"){
fputs($sc, "$domain.$ext\n");
while(!feof($sc)){
$temp = fgets($sc,128);
if(ereg("Whois Server:", $temp)) {
$server = str_replace("Whois Server: ", "", $temp);
$server = trim($server);
}
}
fclose($sc);
if(($sc = fsockopen($server,43))==false){
return false;
}
}

$output="";
fputs($sc,"$domain.$ext\n");
while(!feof($sc)){$output.=fgets($sc,128);}
fclose($sc);
$line = 0;
$line++;
$querywhois .= "<ldiv align=\"center\">";
$querywhois .= "<ltable width=\"90%\" border=\"0\" cellPadding=2>";
$querywhois .= "<ltr><ltd><lb><ldiv align=\"center\"><lfont size=\"4\" color=\"blue\">WHOIS QUERY FOR \"$domain.$ext\"<l/font><l/div><l/b><l/td><l/tr>";
$querywhois .= "<ltr><ltd><lhr><l/td><l/tr><lbr>";
$querywhois .= "<ltr><ltd>";
$output= explode("\n",$output);
$there = false;
foreach ($output as $value){
$querywhois .= "$value<lbr>\n";
}
$querywhois .= "<l/td><l/tr><l/table>";
$querywhois .= "<l/div>";
$querywhois .= "<lbr>";
return $querywhois;
}

//Sample usage
$domain_whois= whois("sonimager","com");
?>

Checking for avaiable domain names

This function accepts a domain name and extension. It will then check the whois server and return if was found or not.

<l?php
//Domain Checker
function check_domain($domain,$ext){
$server="whois.networksolutions.com";
$nomatch="No match for";

$output="";
if(($sc = fsockopen($server,43))==false){
return true;
}
fputs($sc,"$domain.$ext\n");
while(!feof($sc)){
$output.=fgets($sc,128);
}
fclose($sc);
if (eregi($nomatch,$output)){
return true;
} else {
return false;
}
}

//Sample usage
$is_registered = check_domain("sonimager","com");
?>

UPS Tracking

This is a page which will show you the tracking information for any UPS parcel. You will need your UPS userid and access key to use it.

<?php
//////////// begin tracking script ////////////
//$tracking_number is the tracking number
$tracking_number = substr(eregi_replace("[^A-z0-9. -]", "", $tracking_number),0,100); /// just a simple filter and to limit any number to 100 characters for safety sake
$userid_pass = "user"; /// The username and password from UPS (username and password are the same)
$access_key = "key"; //// license key from UPS
$upsURL = "https://www.ups.com/ups.app/xml/Track"; /// This will be provided to you by UPS
$activity = "activity"; /// UPS activity code

///// The below variable is the query string to be posted. /////
$y = "<?xml version=\"1.0\"?><AccessRequest xml:lang=\"en-US\"><AccessLicenseNumber>".$access_key."</AccessLicenseNumber><UserId>".$userid_pass."</UserId><Password>".$userid_pass."</Password></AccessRequest><?xml version=\"1.0\"?><TrackRequest xml:lang=\"en-US\"><Request><TransactionReference><CustomerContext>Example 1</CustomerContext><XpciVersion>1.0001</XpciVersion></TransactionReference><RequestAction>Track</RequestAction><RequestOption>".$activity."</RequestOption></Request><TrackingNumber>".$tracking_number."</TrackingNumber></TrackRequest>";
//////
/////////////////// begin the cURL engine /////////////////////
///////////////////////////////////////////////////////////////
//////////////////// What a powerful utility! /////////////////
///////////////////////////////////////////////////////////////
$ch = curl_init(); /// initialize a cURL session
curl_setopt ($ch, CURLOPT_URL,$upsURL); /// set the post-to url (do not include the ?query+string here!)
curl_setopt ($ch, CURLOPT_HEADER, 0); /// Header control
/// curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); /// Uncomment this line if you are having trouble receiving a response and you know you have everything installed correctly. (Verifies SSL certificate)
curl_setopt($ch, CURLOPT_POST, 1); /// tell it to make a POST, not a GET
curl_setopt($ch, CURLOPT_POSTFIELDS, $y); /// put the query string here starting with "?"
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); /// This allows the output to be set into a variable $xyz
$upsResponse = curl_exec ($ch); /// execute the curl session and return the output to a variable $xyz
curl_close ($ch); /// close the curl session
////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
/////////////////// end the cURL Engine /////////////////


//////////// begin xml parser Class function ////////////
/////////////////////////////////////////////
/////// class function taken from http://www.hansanderson.com/php/xml/class.xml.php.txt

class xml_container {

function store($k,$v) {
$this->{$k}[] = $v;
}

}
class xml {

var $current_tag=array();
var $xml_parser;
var $Version = 1.0;
var $tagtracker = array();

function startElement($parser, $name, $attrs) {

array_push($this->current_tag, $name);

$curtag = implode("_",$this->current_tag);

if(isset($this->tagtracker["$curtag"])) {
$this->tagtracker["$curtag"]++;
} else {
$this->tagtracker["$curtag"]=0;
}


if(count($attrs)>0) {
$j = $this->tagtracker["$curtag"];
if(!$j) $j = 0;

if(!is_object($GLOBALS[$this->identifier]["$curtag"][$j])) {
$GLOBALS[$this->identifier]["$curtag"][$j] = new xml_container;
}

$GLOBALS[$this->identifier]["$curtag"][$j]->store("attributes",$attrs);
}

} // end function startElement



/* when expat hits a closing tag, it fires up this function */

function endElement($parser, $name) {

$curtag = implode("_",$this->current_tag); // piece together tag
// before we pop it off,
// so we can get the correct
// cdata

if(!$this->tagdata["$curtag"]) {
$popped = array_pop($this->current_tag); // or else we screw up where we are
return; // if we have no data for the tag
} else {
$TD = $this->tagdata["$curtag"];
unset($this->tagdata["$curtag"]);
}

$popped = array_pop($this->current_tag);
// we want the tag name for
// the tag above this, it
// allows us to group the
// tags together in a more
// intuitive way.

if(sizeof($this->current_tag) == 0) return; // if we aren't in a tag

$curtag = implode("_",$this->current_tag); // piece together tag
// this time for the arrays

$j = $this->tagtracker["$curtag"];
if(!$j) $j = 0;

if(!is_object($GLOBALS[$this->identifier]["$curtag"][$j])) {
$GLOBALS[$this->identifier]["$curtag"][$j] = new xml_container;
}

$GLOBALS[$this->identifier]["$curtag"][$j]->store($name,$TD); #$this->tagdata["$curtag"]);
unset($TD);
return TRUE;
}



/* when expat finds some internal tag character data,
it fires up this function */

function characterData($parser, $cdata) {
$curtag = implode("_",$this->current_tag); // piece together tag
$this->tagdata["$curtag"] .= $cdata;
}


/* this is the constructor: automatically called when the class is initialized */

function xml($data,$identifier='xml') {

$this->identifier = $identifier;

// create parser object
$this->xml_parser = xml_parser_create();

// set up some options and handlers
xml_set_object($this->xml_parser,$this);
xml_parser_set_option($this->xml_parser,XML_OPTION_CASE_FOLDING,0);
xml_set_element_handler($this->xml_parser, "startElement", "endElement");
xml_set_character_data_handler($this->xml_parser, "characterData");

if (!xml_parse($this->xml_parser, $data, TRUE)) {
sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($this->xml_parser)),
xml_get_current_line_number($this->xml_parser));
}

// we are done with the parser, so let's free it
xml_parser_free($this->xml_parser);

} // end constructor: function xml()


} // thus, we end our class xml
///////////////////////////////////////////////////
/////////// end XML Class ////////////////////////

$obj = new xml($upsResponse,"xml"); /// create the object
$nine = trim($xml["TrackResponse_Response"][0]->ResponseStatusCode[0]);
////////////////////////
if($nine == "1"){
$seven = $xml["TrackResponse_Shipment_ShipTo_Address"][0]->AddressLine1[0] . "\n";
$six = $xml["TrackResponse_Shipment_ShipTo_Address"][0]->AddressLine2[0] . "\n";
$five = $xml["TrackResponse_Shipment_ShipTo_Address"][0]->City[0] . "\n";
$four = $xml["TrackResponse_Shipment_ShipTo_Address"][0]->StateProvinceCode[0] . "\n";
$three = $xml["TrackResponse_Shipment_ShipTo_Address"][0]->PostalCode[0] . "\n";
$two = $xml["TrackResponse_Shipment_ShipTo_Address"][0]->CountryCode[0] . "\n";
$twelve = $xml["TrackResponse_Shipment_Package_PackageWeight_UnitOfMeasurement"][0]->Code[0] . "\n";
$eleven = $xml["TrackResponse_Shipment_Package_PackageWeight"][0]->Weight[0] . "\n";
$thirteen = $xml["TrackResponse_Shipment_Service"][0]->Description[0] . "\n";
///current location
$fourteen = $xml["TrackResponse_Shipment_Package_Activity_ActivityLocation"][0]->Description[0] . "\n";
$eighteen = $xml["TrackResponse_Shipment_Package_Activity_ActivityLocation_Address"][0]->City[0] . "\n";
$nineteen = $xml["TrackResponse_Shipment_Package_Activity_ActivityLocation_Address"][0]->CountryCode[0] . "\n";
$twenty = $xml["TrackResponse_Shipment_Package_Activity_ActivityLocation_Address"][0]->StateProvinceCode[0] . "\n";
$fifteen = $xml["TrackResponse_Shipment_Package_Activity_ActivityLocation"][0]->SignedForByName[0] . "\n";
// end location
$sixteen = $xml["TrackResponse_Shipment_Package_Activity_Status_StatusType"][0]->Description[0] . "\n";
$seventeen = $xml["TrackResponse_Shipment_Package_Activity_Status_StatusType"][0]->Code[0] . "\n";
$twentyfour = $xml["TrackResponse_Shipment_Package_Activity"][0]->Date[0] . "\n";
$twentyfive = $xml["TrackResponse_Shipment_Package_Activity"][0]->Time[0] . "\n";
$yearx = substr("$twentyfour", 0, 4);
$monthx = substr("$twentyfour", 4, 2);
$dayx = substr("$twentyfour", 6, 2);
$hhx = substr("$twentyfive", 0, 2);
$mmx = substr("$twentyfive", 2, 2);
$ssx = substr("$twentyfive", 4, 2);
$seventeen = trim($seventeen);
switch($seventeen){
case I:
$stat = "In transit";
BREAK;
case D:
$stat = "Delivered";
BREAK;
case X:
$stat = "Exception";
BREAK;
case P:
$stat = "Pickup";
BREAK;
case M:
$stat = "Manifest Pickup";
BREAK;
}
?>
<div align="center">
<center><font color="#000080" size="2" face="Verdana">Tracking Number: <b><?php echo $tracking_number ?></b></font>
<table width="50%" border="1" cellpadding="0" cellspacing="0" bordercolor="#0000FF">
<tr><td>
<table border="0" cellspacing="0" cellpadding="4" width="100%">
<tr bgcolor="#ACD2E8">
<td colspan="2" width="360"><font size="2"><b><font color="#FF0000" face="Verdana"><i>Status:</i>
</font><font color="#000080" face="Verdana"> <?php echo $stat ?> </font>
<font color="#000080" face="Verdana">
<?php if($seventeen == "D"){echo("Left at: $fourteen");} ?>
</font></b></font></td>
</tr>
<tr>
<td align="right" nowrap bgcolor="#FFFFCC"><font size="2" face="Verdana"><b>Shipping Method:</b></font></td>
<td width="360" bgcolor="#FFFFCC"><font face="Verdana" size="2" color="#000080"><?php echo $thirteen ?></font></td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFCC"><font size="2" face="Verdana"><b>Weight:</b></font></td>
<td width="360" bgcolor="#FFFFCC"><font face="Verdana" size="2" color="#000080"><?php echo "$eleven $twelve" ?></font></td>
</tr>
<tr>
<td width="360" colspan="2" align="center" bgcolor="#ACD2E8"><font size="2"> </font> <font size="2">
<!--
<font face="Verdana" size="2" color="#FFFFFF"><b><i>Destined for:</i></font></b> -->
<font color="#000080" face="Verdana"><?php echo "$monthx/$dayx/$yearx" ?></font> - <font color="#000080" face="Verdana"><?php echo "$hhx:$mmx:$ssx" ?></font></font>
</font></td>
</tr>

<tr>
<td align="right" bgcolor="#FFFFCC" valign="top">
<b><font face="Verdana" size="2">
<?php if($stat == "I"){$sixteen = trim($sixteen);echo("$sixteen");}else{$sixteen = trim($sixteen);echo("$sixteen");} ?>
:</font></b>
</td>
<td width="360" bgcolor="#FFFFCC">
<font face="Verdana" color="#000080" size="2">
<?php if($eighteen){echo("$eighteen, ");}if($twenty){echo("$twenty ");}if($nineteen){echo("$nineteen");} ?></font>
</td>
</tr>
<tr>
<td colspan="2" width="360"><font face="Verdana" size="2"><b><?php if($seventeen == "D"){echo("<font color='#FF0000'>Signed for by:</font> $fifteen");} ?></b></font></td>
</tr>
<tr>
<td colspan="2" width="360">

</td>
</tr>
</table>
</td>
</tr></table>
</center>
</div>


<?php
}else{
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
$eight = $xml["TrackResponse_Response_Error"][0]->ErrorDescription[0];
echo "<center><b><font color='#FF0000'>".$eight."</font></b></center>";
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
} /// end if nine is 1 or 0
/////////////////
/////////// end xml parser /////
} ///// end if action is track
?>
<BR>
<?php
if($nine == "1"){
$bgcolor = "#E1E1E1";
echo("<center><b>Package History</b></center>
<font face=\"Verdana\" size=\"1\">
<table border='0' align=\"center\"><tr><td nowrap width='20%' bgcolor='#C0C0C0'><B><font face=\"Verdana\" color=\"#000000\" size=\"1\">Date</font></b></td><td nowrap width='20%' bgcolor='#C0C0C0'><B><font face=\"Verdana\" color=\"#000000\" size=\"1\">Time</font></b></td><td nowrap width='20%' bgcolor='#C0C0C0'><B><font face=\"Verdana\" color=\"#000000\" size=\"1\">Location</font></b></td><td width='40%' width='20%' bgcolor='#C0C0C0'><B><font face=\"Verdana\" color=\"#000000\" size=\"1\">Activity</font></b></td></tr>");
for($i=0;$i<count($xml["TrackResponse_Shipment_Package_Activity"]);$i++) {
$twentyone = $xml["TrackResponse_Shipment_Package_Activity_Status_StatusType"][$i]->Description[0] . "\n";
$twentytwo = $xml["TrackResponse_Shipment_Package_Activity"][$i]->Date[0] . "\n";
$twentythree = $xml["TrackResponse_Shipment_Package_Activity"][$i]->Time[0] . "\n";
$twentyfour = $xml["TrackResponse_Shipment_Package_Activity_ActivityLocation_Address"][$i]->City[0] . "\n";
$twentyfive = $xml["TrackResponse_Shipment_Package_Activity_ActivityLocation_Address"][$i]->StateProvinceCode[0] . "\n";
$twentysix = $xml["TrackResponse_Shipment_Package_Activity_ActivityLocation_Address"][$i]->CountryCode[0] . "\n";


$year = substr("$twentytwo", 0, 4);
$month = substr("$twentytwo", 4, 2);
$day = substr("$twentytwo", 6, 2);

$hh = substr("$twentythree", 0, 2);
$mm = substr("$twentythree", 2, 2);
$ss = substr("$twentythree", 4, 2);
echo("<tr>");
if($xday != $day){

if($bgcolor == "#E1E1E1"){
$bgcolor = "#EFEEED";
///echo("E1E1E1");
}else{
$bgcolor = "#E1E1E1";
///echo("EFEEED");
}

echo("<td nowrap width='20%' bgcolor='".$bgcolor."'><B><font face=\"Verdana\" color=\"#000080\" size=\"1\">".$month."/".$day."/".$year."</font></b></td>");

}else{
echo("<td nowrap width='20%' bgcolor='".$bgcolor."'> </td>");
}

$xmonth = $month;
$xday = $day;
$xyear = $xyear;

echo("<td nowrap width='20%' bgcolor='".$bgcolor."'><font face=\"Verdana\" color=\"#000000\" size=\"1\"><i>".$hh.":".$mm.":".$ss."</i></font></td><td nowrap width='20%' bgcolor='".$bgcolor."'><font face=\"Verdana\" color=\"#000000\" size=\"1\">".$twentyfour." ".$twentyfive." ".$twentysix."</font></td><td width='40%' bgcolor='".$bgcolor."'><font face=\"Verdana\" color=\"#000080\" size=\"1\">".$twentyone."</font></td></tr>");
}

echo("
</table>
</font>
<BR>");

echo("<font face=\"Verdana\" color=\"#000000\" size=\"1\">Information last updated: ".date("F j, Y, g:i a T").".<BR><BR>
</font>
");
/// end if 17 is X
?>
<BR>
<!-- end main content -->

Associating numbers with st,nd,th or rd

This function takes in an Array and insures that there are no duplicates, if any removes them and returns one without duplicates.

<?php

//Function to remove duplicated from an array
function cleardub($array){
$x=0;
for($i=0;$i<count($array);$i++){
$cur = $array[$i];
$found = false;
for($u=0;$u<count($newarray);$u++){

if(eregi($cur,$newarray[$u])){
$found = true;
}
}
if($found == false){
$newarray[$x] = $cur;
$x++;
}
}
return $newarray;
}
?>

Associating numbers with st,nd,th or rd

This function takes a number and ordnalize it accordingly. It associates a number with either 1st,2nd,3rd,4th and so on.

<?php

//Function to ordanlize a number
function ord_lize($num) {
if (!is_numeric($num))
return $num;
if ($num >= 11 and $num <= 19)
return $num."<font size='3'>th</font>";
elseif ( $num % 10 == 1 )
return $num."<font size='3'>st</font>";
elseif ( $num % 10 == 2 )
return $num."<font size='3'>nd</font>";
elseif ( $num % 10 == 3 )
return $num."<font size='3'>rd</font>";
else
return $num."<font size='3'>th</font>";
}
?>

Formatting HTML text to be user friendly

This function takes in HTML text, and returns regular text. It mainly strips out HTML and Javascript.

<?php

//Function to strip away HTML and JAVASCRIPT tags
function format_string($string){
$search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
"'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags
"'([\r\n])[\s]+'", // Strip out white space
"'&(quot|#34);'i", // Replace HTML entities
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(\d+);'e"); // evaluate as php

$replace = array ("",
"",
"\\1",
"\"",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
"chr(\\1)");
$text = preg_replace($search, $replace, $string);

$t_na = str_replace("\r\n"," ",$text);
$t_nb = str_replace("'"," ",$t_na);
$t_nc = str_replace('"'," ",$t_nb);
$t_nd = str_replace("\\"," ",$t_nc);
$t_nb = str_replace("<?","[PHP]",$t_na);
$t_nb = str_replace("<?php","[PHP]",$t_na);
$t_nb = str_replace("?>","[/PHP]",$t_na);

return $t_nd;
}
?>

Thanks For Showing Interest In My Posts