Location: PHPKode > scripts > Simple AdSense Insert > simple-adsense-insert/simple-adsense-insert.php
<?php
/*
Plugin Name: Simple AdSense Insert
Plugin URI: http://www.artiss.co.uk/simple-adsense-insert
Description: Displays an AdSense advert in your WordPress blog.
Version: 1.2
Author: David Artiss
Author URI: http://www.artiss.co.uk
*/
function simple_adsense_insert($paras_in,$ad_slot="",$ad_width="",$ad_height="") {
    $ad_client=get_adsense_parameters($paras_in,"client");
    if ($ad_client=="") {
        $ad_client=$paras_in;
    } else {
        $ad_slot=get_adsense_parameters($paras_in,"slot");
        $ad_width=get_adsense_parameters($paras_in,"width");
        $ad_height=get_adsense_parameters($paras_in,"height");
    }
    if (($ad_client=="")or($ad_slot=="")or($ad_width=="")or($ad_height=="")) {
        echo adsense_insert_error("Missing AdSense Data");
    } else {
        echo "<script type=\"text/javascript\"><!--\n";
        echo "google_ad_client=\"".$ad_client."\"; ";
        echo "google_ad_slot=\"".$ad_slot."\"; ";
        echo "google_ad_width=".$ad_width."; ";
        echo "google_ad_height=".$ad_height.";\n";
        echo "//-->\n";
        echo "</script>\n";
        echo "<script type=\"text/javascript\" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\"></script>\n";
    }
}
// Function to report an error
function adsense_insert_error($errorin) {
    return "<p style=\"color: #f00; font-weight: bold;\">Simple Adsense Insert: ".$errorin."</p>\n";
}
// Function to extract parameters from an input string (1.0)
function get_adsense_parameters($input,$para) {
    $start=strpos(strtolower($input),$para."=");
    $content="";
    if ($start!==false) {
        $start=$start+strlen($para)+1;
        $end=strpos(strtolower($input),"&",$start);
        if ($end!==false) {$end=$end-1;} else {$end=strlen($input);}
        $content=substr($input,$start,$end-$start+1);
    }
    return $content;
}
?>
Return current item: Simple AdSense Insert