Web Development
 
Your Ad Here
Clean our odd characters pasted from word to form fields (javascript version) 
Here is the javascript version to clean out odd characters pasted from word into form fields:

function html_fix(html) {

html = html.replace(/<\\?\?xml[^>]*>/ig,"");
html = html.replace(/<\/?o:p[^>]*>/ig,"");
html = html.replace(/<\/?v:[^>]*>/ig,"");
html = html.replace(/<\/?o:[^>]*>/ig,"");
html = html.replace(/<\/?st1:[^>]*>/ig,"");
html = html.replace(/ /ig,"");
html = html.replace(/<\/?SPAN[^>]*>/ig,"");
html = html.replace(/<\/?FONT[^>]*>/ig,"");
html = html.replace(/<BR[^>]*>/ig,"<BR />");
html = html.replace(/<P[^>]*>/ig,"");
html = html.replace(/<\/P[^>]*>/ig,"<BR />");
html = html.replace(/<![^>]*>/ig,"");
html = html.replace(/¡/g,"¡");
html = html.replace(/¤/g,"¤");
html = html.replace(/¢/g,"¢");
html = html.replace(/£/g,"£");
html = html.replace(/¥/g,"¥");
html = html.replace(/¦/g,"¦");
html = html.replace(/§/g,"§");
html = html.replace(/¨/g,"¨");
html = html.replace(/©/g,"©");
html = html.replace(/ª/g,"ª");
html = html.replace(/«/g,"«");
html = html.replace(/¬/g,"¬");
html = html.replace(/­/g,"­");
html = html.replace(/®/g,"®");
html = html.replace(/™/g,"™");
html = html.replace(/¯/g,"¯");
html = html.replace(/°/g,"°");
html = html.replace(/±/g,"±");
html = html.replace(/²/g,"²");
html = html.replace(/³/g,"³");
html = html.replace(/´/g,"´");
html = html.replace(/µ/g,"µ");
html = html.replace(/¶/g,"¶");
html = html.replace(/·/g,"·");
html = html.replace(/¸/g,"¸");
html = html.replace(/¹/g,"¹");
html = html.replace(/º/g,"º");
html = html.replace(/»/g,"»");
html = html.replace(/¼/g,"¼");
html = html.replace(/½/g,"½");
html = html.replace(/¾/g,"¾");
html = html.replace(/¿/g,"¿");
html = html.replace(/×/g,"×");
html = html.replace(/÷/g,"÷");
html = html.replace(/À/g,"À");
html = html.replace(/Á/g,"Á");
html = html.replace(/Â/g,"Â");
html = html.replace(/Ã/g,"Ã");
html = html.replace(/Ä/g,"Ä");
html = html.replace(/Å/g,"Å");
html = html.replace(/Æ/g,"Æ");
html = html.replace(/Ç/g,"Ç");
html = html.replace(/È/g,"È");
html = html.replace(/É/g,"É");
html = html.replace(/Ê/g,"Ê");
html = html.replace(/Ë/g,"Ë");
html = html.replace(/Ì/g,"Ì");
html = html.replace(/Í/g,"Í");
html = html.replace(/Î/g,"Î");
html = html.replace(/Ï/g,"Ï");
html = html.replace(/Ð/g,"Ð");
html = html.replace(/Ñ/g,"Ñ");
html = html.replace(/Ò/g,"Ò");
html = html.replace(/Ó/g,"Ó");
html = html.replace(/Ô/g,"Ô");
html = html.replace(/Õ/g,"Õ");
html = html.replace(/Ö/g,"Ö");
html = html.replace(/Ø/g,"Ø");
html = html.replace(/Ù/g,"Ù");
html = html.replace(/Ú/g,"Ú");
html = html.replace(/Û/g,"Û");
html = html.replace(/Ü/g,"Ü");
html = html.replace(/Ý/g,"Ý");
html = html.replace(/Þ/g,"Þ");
html = html.replace(/ß/g,"ß");
html = html.replace(/à/g,"à");
html = html.replace(/á/g,"á");
html = html.replace(/â/g,"â");
html = html.replace(/ã/g,"ã");
html = html.replace(/ä/g,"ä");
html = html.replace(/å/g,"å");
html = html.replace(/æ/g,"æ");
html = html.replace(/ç/g,"ç");
html = html.replace(/è/g,"è");
html = html.replace(/é/g,"é");
html = html.replace(/ê/g,"ê");
html = html.replace(/ë/g,"ë");
html = html.replace(/ì/g,"ì");
html = html.replace(/í/g,"í");
html = html.replace(/î/g,"î");
html = html.replace(/ï/g,"ï");
html = html.replace(/ð/g,"ð");
html = html.replace(/ñ/g,"ñ");
html = html.replace(/ò/g,"ò");
html = html.replace(/ó/g,"ó");
html = html.replace(/ô/g,"ô");
html = html.replace(/õ/g,"õ");
html = html.replace(/ö/g,"ö");
html = html.replace(/ø/g,"ø");
html = html.replace(/ù/g,"ù");
html = html.replace(/ú/g,"ú");
html = html.replace(/û/g,"û");
html = html.replace(/ü/g,"ü");
html = html.replace(/ý/g,"ý");
html = html.replace(/þ/g,"þ");
html = html.replace(/ÿ/g,"ÿ");
html = html.replace(/“/g,"“");
html = html.replace(/”/g,"”");
html = html.replace(/Œ/g,"Œ");
html = html.replace(/œ/g,"œ");
html = html.replace(/Š/g,"Š");
html = html.replace(/š/g,"š");
html = html.replace(/Ÿ/g,"Ÿ");
html = html.replace(/ˆ/g,"ˆ");
html = html.replace(/˜/g,"˜");
html = html.replace(/–/g,"–");
html = html.replace(/—/g,"—");
html = html.replace(/‘/g,"‘");
html = html.replace(/’/g,"’");
html = html.replace(/‚/g,"‚");
html = html.replace(/“/g,"“");
html = html.replace(/”/g,"”");
html = html.replace(/„/g,"„");
html = html.replace(/†/g,"†");
html = html.replace(/‡/g,"‡");
html = html.replace(/…/g,"…");
html = html.replace(/‰/g,"‰");
html = html.replace(/‹/g,"‹");
html = html.replace(/›/g,"›");
html = html.replace(/€/g,"€");

return html;
}

[ add comment ] ( 18 views )   |  permalink  |   ( 3.1 / 217 )
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.8 / 121 )
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 ] ( 7 views )   |  permalink  |   ( 3 / 133 )
Ajax calls using prototype 
Protoype is an excellent javascript framework that provides an easy way to make ajax calls.

Here is the sample code of how to make the call:

//first I am passing a variable that I call id, this would be the row id for the database table being used, for example: if I'm updating the record with the id of 4, I would call: javascript:dosomethingAjax('4');
//the id is passed to the file dosome.php that will handle whatever it is you are trying to do
//if you want to pass more variables through the ajax call you would use commas to separate them, for example: parameters: {u: id, name: 'John', age: 24}

function dosomethingAjax(id) {
var myAjax = new Ajax.Request('dosome.php',
{method: 'get', parameters: {u: id},
onComplete: handleResponse});
}
//once dosome.php gets processed, the ajax call is complete and the following function is called, in this case, I am putting the results inside a div with the id of displayResults
function handleResponse(transport) {
document.getElementById('displayResults').innerHTML = transport.responseText;
}

//here is how to setup the dosome.php

<?php
//the variable u is being passed by the ajax call listed above
$id = $_GET['u'];
//do something like update or insert or select
echo "Success!";
?>

[ add comment ] ( 19 views )   |  permalink  |  related link  |   ( 3 / 122 )
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.1 / 172 )

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


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