Web Development
 
Your Ad Here
Cleaning out odd characters and multilingual characters when copyed from Word into your form fields 
If you need to convert from one encoding type to another: this helps when certain multi-lingual characters don't show up properly on your browser.

$content = iconv("ISO-8859-1","UTF-8", $content);

Here is a function that cleans out odd characters and converts them to proper usage when users copy from Word into your form field(including international symbols):

function html_fix($html)
{
$html = preg_replace('/¡/','¡',$html);
$html = preg_replace('/¤/','¤',$html);
$html = preg_replace('/¢/','¢',$html);
$html = preg_replace('/£/','£',$html);
$html = preg_replace('/¥/','¥',$html);
$html = preg_replace('/¦/','¦',$html);
$html = preg_replace('/§/','§',$html);
$html = preg_replace('/¨/','¨',$html);
$html = preg_replace('/©/','©',$html);
$html = preg_replace('/ª/','ª',$html);
$html = preg_replace('/«/','«',$html);
$html = preg_replace('/¬/','¬',$html);
$html = preg_replace('/­/','­',$html);
$html = preg_replace('/®/','®',$html);
$html = preg_replace('/™/','™',$html);
$html = preg_replace('/¯/','¯',$html);
$html = preg_replace('/°/','°',$html);
$html = preg_replace('/±/','±',$html);
$html = preg_replace('/²/','²',$html);
$html = preg_replace('/³/','³',$html);
$html = preg_replace('/´/','´',$html);
$html = preg_replace('/µ/','µ',$html);
$html = preg_replace('/¶/','¶',$html);
$html = preg_replace('/·/','·',$html);
$html = preg_replace('/¸/','¸',$html);
$html = preg_replace('/¹/','¹',$html);
$html = preg_replace('/º/','º',$html);
$html = preg_replace('/»/','»',$html);
$html = preg_replace('/¼/','¼',$html);
$html = preg_replace('/½/','½',$html);
$html = preg_replace('/¾/','¾',$html);
$html = preg_replace('/¿/','¿',$html);
$html = preg_replace('/×/','×',$html);
$html = preg_replace('/÷/','÷',$html);
$html = preg_replace('/À/','À',$html);
$html = preg_replace('/Á/','Á',$html);
$html = preg_replace('/Â/','Â',$html);
$html = preg_replace('/Ã/','Ã',$html);
$html = preg_replace('/Ä/','Ä',$html);
$html = preg_replace('/Å/','Å',$html);
$html = preg_replace('/Æ/','Æ',$html);
$html = preg_replace('/Ç/','Ç',$html);
$html = preg_replace('/È/','È',$html);
$html = preg_replace('/É/','É',$html);
$html = preg_replace('/Ê/','Ê',$html);
$html = preg_replace('/Ë/','Ë',$html);
$html = preg_replace('/Ì/','Ì',$html);
$html = preg_replace('/Í/','Í',$html);
$html = preg_replace('/Î/','Î',$html);
$html = preg_replace('/Ï/','Ï',$html);
$html = preg_replace('/Ð/','Ð',$html);
$html = preg_replace('/Ñ/','Ñ',$html);
$html = preg_replace('/Ò/','Ò',$html);
$html = preg_replace('/Ó/','Ó',$html);
$html = preg_replace('/Ô/','Ô',$html);
$html = preg_replace('/Õ/','Õ',$html);
$html = preg_replace('/Ö/','Ö',$html);
$html = preg_replace('/Ø/','Ø',$html);
$html = preg_replace('/Ù/','Ù',$html);
$html = preg_replace('/Ú/','Ú',$html);
$html = preg_replace('/Û/','Û',$html);
$html = preg_replace('/Ü/','Ü',$html);
$html = preg_replace('/Ý/','Ý',$html);
$html = preg_replace('/Þ/','Þ',$html);
$html = preg_replace('/ß/','ß',$html);
$html = preg_replace('/à/','à',$html);
$html = preg_replace('/á/','á',$html);
$html = preg_replace('/â/','â',$html);
$html = preg_replace('/ã/','ã',$html);
$html = preg_replace('/ä/','ä',$html);
$html = preg_replace('/å/','å',$html);
$html = preg_replace('/æ/','æ',$html);
$html = preg_replace('/ç/','ç',$html);
$html = preg_replace('/è/','è',$html);
$html = preg_replace('/é/','é',$html);
$html = preg_replace('/ê/','ê',$html);
$html = preg_replace('/ë/','ë',$html);
$html = preg_replace('/ì/','ì',$html);
$html = preg_replace('/í/','í',$html);
$html = preg_replace('/î/','î',$html);
$html = preg_replace('/ï/','ï',$html);
$html = preg_replace('/ð/','ð',$html);
$html = preg_replace('/ñ/','ñ',$html);
$html = preg_replace('/ò/','ò',$html);
$html = preg_replace('/ó/','ó',$html);
$html = preg_replace('/ô/','ô',$html);
$html = preg_replace('/õ/','õ',$html);
$html = preg_replace('/ö/','ö',$html);
$html = preg_replace('/ø/','ø',$html);
$html = preg_replace('/ù/','ù',$html);
$html = preg_replace('/ú/','ú',$html);
$html = preg_replace('/û/','û',$html);
$html = preg_replace('/ü/','ü',$html);
$html = preg_replace('/ý/','ý',$html);
$html = preg_replace('/þ/','þ',$html);
$html = preg_replace('/ÿ/','ÿ',$html);
$html = preg_replace('/“/','“',$html);
$html = preg_replace('/”/','”',$html);
$html = preg_replace('/Œ/','Œ',$html);
$html = preg_replace('/œ/','œ',$html);
$html = preg_replace('/Š/','Š',$html);
$html = preg_replace('/š/','š',$html);
$html = preg_replace('/Ÿ/','Ÿ',$html);
$html = preg_replace('/ˆ/','ˆ',$html);
$html = preg_replace('/˜/','˜',$html);
$html = preg_replace('/–/','–',$html);
$html = preg_replace('/—/','—',$html);
$html = preg_replace('/‘/','‘',$html);
$html = preg_replace('/’/','’',$html);
$html = preg_replace('/‚/','‚',$html);
$html = preg_replace('/“/','“',$html);
$html = preg_replace('/”/','”',$html);
$html = preg_replace('/„/','„',$html);
$html = preg_replace('/†/','†',$html);
$html = preg_replace('/‡/','‡',$html);
$html = preg_replace('/…/','…',$html);
$html = preg_replace('/‰/','‰',$html);
$html = preg_replace('/‹/','‹',$html);
$html = preg_replace('/›/','›',$html);
$html = preg_replace('/€/','€',$html);
return $html;
}

[ add comment ] ( 3 views )   |  permalink  |   ( 2.9 / 192 )
Create a dynamic rss xml feed with php class 
class RSSFeed {
// VARIABLES
// channel vars
var $channel_url;
var $channel_title;
var $channel_description;
var $channel_lang;
var $channel_copyright;
var $channel_date;
var $channel_creator;
var $channel_subject;
// image
var $image_url;
// items
var $items = array();
var $nritems;
// FUNCTIONS
// constructor
function RSSFeed() {
$this->nritems=0;
$this->channel_url='';
$this->channel_title='';
$this->channel_description='';
$this->channel_lang='';
$this->channel_copyright='';
$this->channel_date='';
$this->channel_creator='';
$this->channel_subject='';
$this->image_url='';
}
// set channel vars
function SetChannel($url, $title, $description, $lang, $copyright, $creator, $subject) {
$this->channel_url=$url;
$this->channel_title=$title;
$this->channel_description=$description;
$this->channel_lang=$lang;
$this->channel_copyright=$copyright;
$this->channel_date=date("Y-m-d").'T'.date("H:i:s").'+01:00';
$this->channel_creator=$creator;
$this->channel_subject=$subject;
}
// set image
function SetImage($url) {
$this->image_url=$url;
}
// set item
function SetItem($url, $title, $description) {
$this->items[$this->nritems]['url']=$url;
$this->items[$this->nritems]['title']=$title;
$this->items[$this->nritems]['description']=$description;
$this->nritems++;
}
// output feed
function Output() {
$output = '<?xml version="1.0" encoding="iso-8859-1"?>'."\n";
$output .= '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">'."\n";
$output .= '<channel rdf:about="'.$this->channel_url.'">'."\n";
$output .= '<title>'.$this->channel_title.'</title>'."\n";
$output .= '<link>'.$this->channel_url.'</link>'."\n";
$output .= '<description>'.$this->channel_description.'</description>'."\n";
$output .= '<dc:language>'.$this->channel_lang.'</dc:language>'."\n";
$output .= '<dc:rights>'.$this->channel_copyright.'</dc:rights>'."\n";
$output .= '<dc:date>'.$this->channel_date.'</dc:date>'."\n";
$output .= '<dc:creator>'.$this->channel_creator.'</dc:creator>'."\n";
$output .= '<dc:subject>'.$this->channel_subject.'</dc:subject>'."\n";
$output .= '<items>'."\n";
$output .= '<rdf:Seq>';
for($k=0; $k<$this->nritems; $k++) {
$output .= '<rdf:li rdf:resource="'.$this->items[$k]['url'].'"/>'."\n";
};
$output .= '</rdf:Seq>'."\n";
$output .= '</items>'."\n";
$output .= '<image rdf:resource="'.$this->image_url.'"/>'."\n";
$output .= '</channel>'."\n";
for($k=0; $k<$this->nritems; $k++) {
$output .= '<item rdf:about="'.$this->items[$k]['url'].'">'."\n";
$output .= '<title>'.$this->items[$k]['title'].'</title>'."\n";
$output .= '<link>'.$this->items[$k]['url'].'</link>'."\n";
$output .= '<description>'.$this->items[$k]['description'].'</description>'."\n";
$output .= '<feedburner:origLink>'.$this->items[$k]['url'].'</feedburner:origLink>'."\n";
$output .= '</item>'."\n";
};
$output .= '</rdf:RDF>'."\n";
return $output;
}
};

Use the class this way:

$myfeed = new RSSFeed();
$myfeed->SetChannel('http://www.yousite.com/site-feed.xml', 'Title of your site', 'description of your site', 'en-us', 'Copyright applies', 'author', 'type of site');
$myfeed->SetImage('http://www.yoursite.com/logo.gif');
//here is an example using mysql to receive information
$sql = "select id, title, content, date from table order by date desc";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {

$link = "http://www.yourstory.com/index.php?s=".$row[0];

//strip all html tags
$description = strip_tags($row[2]);

$myfeed->SetItem($link,$row[1],$description);
}

$out = $myfeed->output();
//you have two options, you can just echo the feed or same it as an xml file in your server

// echo $out;
$file = "site-feed.xml";
$fh = fopen($file,'w');
fwrite($fh,$out);
fclose($fh);

////End of code////
//Validate your rss feed: http://feedvalidator.org



[ add comment ] ( 8 views )   |  permalink  |   ( 3 / 207 )
Form Select State & Show current selection 
In this very basic example, the form is going to the same page on submit, assigning the state value to a session and showing the current selection in the drop down.

<?php
$_SESSION['STATE'] = $_POST['STATE'];

$temp_st = "type".$_SESSION['STATE'];
$$temp_st = " selected";
?>

<form name="form" method="post" action="">
<select name="STATE" id="STATE"
<option value="AL"<?php echo $typeAL; ?>>Alabama</option>
<option value="AK"<?php echo $typeAK; ?>>Alaska</option>
<option value="AZ"<?php echo $typeAZ; ?>>Arizona</option>
<option value="AR"<?php echo $typeAR; ?>>Arkansas</option>
<option value="CA"<?php echo $typeCA; ?>>California</option>
<option value="CO"<?php echo $typeCO; ?>>Colorado</option>
<option value="CT"<?php echo $typeCT; ?>>Connecticut</option>
<option value="DE"<?php echo $typeDE; ?>>Delaware</option>
<option value="DC"<?php echo $typeDC; ?>>District of Columbia</option>
<option value="FL"<?php echo $typeFL; ?>>Florida</option>
<option value="GA"<?php echo $typeGA; ?>>Georgia</option>
<option value="HI"<?php echo $typeHI; ?>>Hawaii</option>
<option value="ID"<?php echo $typeID; ?>>Idaho</option>
<option value="IL"<?php echo $typeIL; ?>>Illinois</option>
<option value="IN"<?php echo $typeIN; ?>>Indiana</option>
<option value="IA"<?php echo $typeIA; ?>>Iowa</option>
<option value="KS"<?php echo $typeKS; ?>>Kansas</option>
<option value="KY"<?php echo $typeKY; ?>>Kentucky</option>
<option value="LA"<?php echo $typeLA; ?>>Louisiana</option>
<option value="ME"<?php echo $typeME; ?>>Maine</option>
<option value="MD"<?php echo $typeMD; ?>>Maryland</option>
<option value="MA"<?php echo $typeMA; ?>>Massachusetts</option>
<option value="MI"<?php echo $typeMI; ?>>Michigan</option>
<option value="MN"<?php echo $typeMN; ?>>Minnesota</option>
<option value="MS"<?php echo $typeMS; ?>>Mississippi</option>
<option value="MO"<?php echo $typeMO; ?>>Missouri</option>
<option value="MT"<?php echo $typeMT; ?>>Montana</option>
<option value="NE"<?php echo $typeNE; ?>>Nebraska</option>
<option value="NV"<?php echo $typeNV; ?>>Nevada</option>
<option value="NH"<?php echo $typeNH; ?>>New Hampshire</option>
<option value="NJ"<?php echo $typeNJ; ?>>New Jersey</option>
<option value="NM"<?php echo $typeNM; ?>>New Mexico</option>
<option value="NY"<?php echo $typeNY; ?>>New York</option>
<option value="NC"<?php echo $typeNC; ?>>North Carolina</option>
<option value="ND"<?php echo $typeND; ?>>North Dakota</option>
<option value="OH"<?php echo $typeOH; ?>>Ohio</option>
<option value="OK"<?php echo $typeOK; ?>>Oklahoma</option>
<option value="OR"<?php echo $typeOR; ?>>Oregon</option>
<option value="PA"<?php echo $typePA; ?>>Pennsylvania</option>
<option value="RI"<?php echo $typeRI; ?>>Rhode Island</option>
<option value="SC"<?php echo $typeSC; ?>>South Carolina</option>
<option value="SD"<?php echo $typeSD; ?>>South Dakota</option>
<option value="TN"<?php echo $typeTN; ?>>Tennessee</option>
<option value="TX"<?php echo $typeTX; ?>>Texas</option>
<option value="UT"<?php echo $typeUT; ?>>Utah</option>
<option value="VT"<?php echo $typeVT; ?>>Vermont</option>
<option value="VA"<?php echo $typeVA; ?>>Virginia</option>
<option value="WA"<?php echo $typeWA; ?>>Washington</option>
<option value="WV"<?php echo $typeWV; ?>>West Virginia</option>
<option value="WI"<?php echo $typeWI; ?>>Wisconsin</option>
<option value="WY"<?php echo $typeWY; ?>>Wyoming</option>
</select>
<input type="submit" name="Submit" value="Submit"/>
</form>

[ 3 comments ] ( 17 views )   |  permalink  |   ( 3 / 237 )
Date drop down for PHP forms 
// created by www.dpwebservices.net

function listbox_day ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($dayf=01;$dayf<=31;$dayf++) {
if ($default == $dayf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".date(d, mktime(0,0,0,0,$dayf,2000))."\" $selected class=\"field\">".date(j, mktime(0,0,0,0,$dayf,2000))."</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_month ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($monthf=01;$monthf<=12;$monthf++) {
if ($default == $monthf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".date(m, mktime(0,0,0,$monthf,1,2000))."\" $selected class=\"field\">".date(M, mktime(0,0,0,$monthf,1,2000))."</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_year ($name, $start, $end, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($yearf=$end;$yearf>=$start;$yearf--) {
if ($default == $yearf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"$yearf\" $selected class=\"field\">$yearf</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_hour ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($hourf=1;$hourf<=12;$hourf++) {
if ($default == $hourf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".date(h, mktime($hourf,0,0,0,0,2000))."\" $selected>".date(g, mktime($hourf,0,0,0,0,2000))."</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_24hour ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($hourf=00;$hourf<=23;$hourf++) {
if ($default == $hourf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".date(H, mktime($hourf,0,0,0,0,2000))."\" $selected>".date(H, mktime($hourf,0,0,0,0,2000))."</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_min ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($minf=00;$minf<=59;$minf++) {
if ($default == $minf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".date(i, mktime(0,$minf,0,0,0,2000))."\" $selected>".date(i, mktime(0,$minf,0,0,0,2000))."</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_week ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
$weekx = '0';
for ($week_count=strftime("%U"); $week_count>=1; $week_count--) {
$weekx ++;
$str = '-'.$week_count.' week Monday';
if (($timestamp = strtotime($str)) === -1) {
$weekmsg = "The string ($str) is bogus";
} else {

$weekmsg = "Week ".$weekx." - ".date('F j',$timestamp);
$weekdate = date(m.'/'.d.'/'.y,$timestamp);

}
// echo $default; weekx to select the week
if ($default == $weekdate) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".$weekdate."\" $selected>".$weekmsg."</option>\n";
}
$result.="</select>\n";
return $result;
}

// onChange=\"MM_goToURL('parent','#');return document.MM_returnValue\"

function listbox_nummon ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($dayf=1;$dayf<=48;$dayf++) {
if ($default == $dayf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".$dayf."\" $selected>".$dayf."</option>\n";
}
$result.="</select>\n";
return $result;
}

/*
example of echos


<?php echo listbox_month("month", 7); ?> /
<?php echo listbox_day("day",23); ?> /
<?php echo listbox_year("year", 1994, 2003, 2001); ?>,&nbsp;
<?php echo listbox_hour("hour", 12); ?>:
<?php echo listbox_min("min", 00); ?>
);
<br>
<?php echo listbox_month("month2", 1); ?> /
<?php echo listbox_day("day2", 2); ?> /
<?php echo listbox_year("year2", 1994, date(Y), 2002); ?>,&nbsp;
<?php echo listbox_hour("hour2", 11); ?>:
<?php echo listbox_min("min2", 59); ?>

Below is to call the current "week - month day" back to week 1 in a pulldown menu...
echo listbox_week("week", strftime("%U"));

*/


[ add comment ] ( 7 views )   |  permalink  |   ( 3 / 185 )
PHP Dynamic Variables 
Simple PHP code of the day....

Example Scenario: Let's say you have multiple loops coming out of the database, and you are adding "checked" to specific checkboxes.

Normally you could just do something like this:

$temp = "myVarName".$i;
$$temp = "checked";

But now let's say you have multiple loops breaking out in your <tr>...
Scary stuff people...

How would you echo $$temp ?
HINT: <?php echo $$temp; ?> will not work in this scenario...

hmm give up?

Here's your Answer:

${"myVarName".$i}

And that's the Simple PHP code of the day...


[ add comment ] ( 8 views )   |  permalink  |   ( 3 / 191 )

| 1 | 2 | 3 | 4 | Next> Last>>


Home | Portfolio | Hosting | Web Development | Contact Us
© 2007 dpwebservices.net. All right reserved.