August 1, 2010

PHP Email Validation

Below PHP function returns true if the email address given as parameter is valid, false otherwise.

PHP code:

function validEmail($email)
{
    if (preg_match(‘/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is’, $email))
        {return true;}
    else
        {return false;}
}
June 27, 2010

HTML5 (re)set stylesheet

This CSS stylesheet sets default values for HTML5 tags.

CSS code:

/* HTML5 CSS RESET */

html, body,
a, abbr, address, article, aside, audio
b, blockquote,
canvas, caption, cite, code,
dd, del, details, dfn, div, dl, dt,
em,
fieldset, figcaption, figure, footer, form,
h1, h2, h3, h4, h5, h6, header, hgroup,
i, iframe, img, ins,
kbd,
label, legend, li,
mark, menu, meter,
nav,
object, ol,
p, pre,
q,
samp, section, small, span, sub, summary, sup, strong,
table, tbody, td, tfoot, th, thead, time, tr,
ul,
var, video
{margin:0;
padding:0;
border:0;
outline:0;
font-weight:inherit;
font-style:inherit;
font-size:100%;
font-family:inherit;
vertical-align:baseline;}

body{line-height:1; color:black; background:white;}

:focus{outline:0;}
a{text-decoration:none;}
abbr[title], dfn[title]{border-bottom:1px dotted #000; cursor:help;}
article, aside, canvas, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary{display:block;}
blockquote:before, blockquote:after, q:before, q:after{content:"";}
blockquote, q{quotes:"" "";}
caption, th, td{text-align:left; font-weight:normal;}
del{text-decoration:line-through;}
hr{display:block; height:1px; border:0; border-top:1px solid #cccccc; margin:1em 0; padding:0;}
input, select{vertical-align:middle;}
ins{background-color:#cfcfcf; text-decoration:none;}
mark{background-color:#cfcfcf; font-style:italic; font-weight:bold;}
menu, ol, ul{list-style:none;}
table{border-collapse:collapse; border-spacing:0;}

/* HTML5 END CSS RESET */

June 10, 2010

JavaScript Email Validation

Below JavaScript function returns true if the email address given as parameter is valid, false otherwise.

JavaScript code:

function validEmail(email)
{
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(email))
        {return true;}
    return false;
}
June 7, 2010

Send an email with php (HTML content supported)

Here is a php function with which you can send an email with normal text or in html format.

PHP code:

$email_to = ‘Where the email will be sended to.’;
$email_from = ‘From where the email will be sended.’;
$subject = ‘The subject of the email.’;
$message = ‘The content of the email; can be in html format to.’;

sendEmail($email_to,$email_from,$subject,$message);
       
function sendEmail($email_to,$email_from,$subject,$message)
{
    $headers  = ‘MIME-Version: 1.0′ . "\r\n";
    $headers .= ‘Content-type: text/html; charset=iso-8859-1′ . "\r\n";
    $headers .= ‘From:’.$email_from."\r\n"
                     .‘Reply-To:’.$email_from;
       
    mail($email_to, $subject, $message, $headers);
}

May 30, 2010

How to parse a XML file using PHP

Here is an example on how to get data from XML files using PHP.

XML file example:

<?xml version="1.0" encoding="utf-8"?>
<Data>
    <Logo>Logo Test</Logo>
    <Title>Title Test</Title>
    <Subtitle>Subtitle Test</Subtitle>
    <Menu>
        <Item Name="Item 1" DataPath="DP Test" />
        <Item Name="Item 2" DataPath="DP Test" />
        <Item Name="Item 3">
            <Item Name="SubItem 1" DataPath="DP Test" />
            <Item Name="SubItem 2" DataPath="DP Test" />
            <Item Name="SubItem 3" DataPath="DP Test" />
            <Item Name="SubItem 4" DataPath="DP Test" />
            <Item Name="SubItem 5" DataPath="DP Test" />
        </Item>
        <Item Name="Item 4">
            <Item Name="SubItem 1" DataPath="DP Test" />
            <Item Name="SubItem 2" DataPath="DP Test" />
            <Item Name="SubItem 3" DataPath="DP Test" />
        </Item>
        <Item Name="Item 5" Type="T Test" DataPath="DP Test" />
    </Menu>
</Data>

PHP code:

$xmlDoc = new DOMDocument(); // Load a XML file.
$xmlDoc->load(‘menu.xml’);
       
$XMLNode = $xmlDoc->documentElement;

//We go through all nodes from the XML and test their names. Depending on their names we take necessary actions.
foreach ($XMLNode->childNodes as $currentNode)
{
    if (strtolower($currentNode->nodeName) == ‘logo’)
        {echo $currentNode->nodeValue.‘<br />’;} // Read a node value.
    if (strtolower($currentNode->nodeName) == ‘title’)
        {echo $currentNode->nodeValue.‘<br />’;}               
    if (strtolower($currentNode->nodeName) == ‘subtitle’)
        {echo $currentNode->nodeValue.‘<br />’;}               
    if (strtolower($currentNode->nodeName) == ‘menu’)
    {
        foreach ($currentNode->childNodes as $menuItem)
        {
            // Test if node has children.              
            if (strtolower($menuItem->nodeName) == ‘item’ && $menuItem->hasChildNodes())
            {
                echo $menuItem->getAttribute(‘Name’).‘<br />’; // Read a node attribute.
       
                foreach ($menuItem->childNodes as $submenuItem)
                {
                    if (strtolower($submenuItem->nodeName) == ‘item’)
                    {
                        echo $submenuItem->getAttribute(‘Name’);
                        echo $submenuItem->getAttribute(‘DataPath’);
                    }                                  
                }
            }
            elseif (strtolower($menuItem->nodeName) == ‘item’)
            {
                echo $menuItem->getAttribute(‘Name’);
                echo $menuItem->getAttribute(‘DataPath’);
            }  
        }
    }
}

April 17, 2010

How to style HTML/XHTML input tag by type with CSS

Use the below CSS code to edit the HTML/XHTML input tag by type.

CSS code:

input[type=button]{}
input[type=checkbox]{}
input[type=file]{}
input[type=image]{}
input[type=password]{}
input[type=radio]{}
input[type=reset]{}
input[type=submit]{}
input[type=text]{}
January 21, 2010

Smooci 2.1.0 WordPress Theme

Need an WordPress Theme for mobiles? Visit SMOOCI.COM

Smooci is a WordPress theme for mobile phones and devices. Use this WordPress plugin to display the theme when your WordPress site is visited on mobiles

January 21, 2010

Smooci (WordPress on Mobiles) – WordPress Plugin

Need an WordPress Theme for mobiles? Visit SMOOCI.COM

Smooci (WordPress on Mobiles) plugin can be used to display a diferent theme when your WordPress site is visited on mobile phones or devices.
The plugin detects the mobile device and displays the theme of your choice. If you encounter a mobile phone or device that doesn’t display the selected theme, please leave a comment to this post.

August 5, 2009

AJAX form request using POST method

Here is a way you can call a server side script with AJAX, using POST method.

JavaScript code:

var xmlHttpVariable; // Declare a global variable.

// HTTP request object.
function GetXmlHttpObject()
{
    var xmlHttp = null;

    try
        {xmlHttp = new XMLHttpRequest();}
    catch (e)
    {
        try
            {xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
        catch (e)
            {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
    }

    return xmlHttp;
}

function callServer()
{
    xmlHttpVariable = new GetXmlHttpObject(); // Call HTTP request object.
    var url = "url"; // Set the URL to the server-side script.
    var variables = "var1=val1&amp;var2=val2"; // Set the variables.
    xmlHttpVariable.onreadystatechange = stateChangedVariable; // Call a function on state change.
    xmlHttpVariable.open("POST",url,true); // Open the URL.
    // Send the proper header information along with the request.
    xmlHttpVariable.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttpVariable.setRequestHeader("Content-length", variables.length);
    xmlHttpVariable.setRequestHeader("Connection", "close");
    xmlHttpVariable.send(variables); // Send the variables.
}

function stateChangedVariable()
{
    if (xmlHttpVariable.readyState == 4) // Values for readyState see below for explanations.
    {
        if (xmlHttpVariable.responseText.replace(/^\s+|\s+$/g, ) == ‘return value’)
            {// Action here.}
    }
}

readyState values:

0 – Represents an “uninitialized” state in which an XMLHttt pRequesobject has been created, but not initialized.

1 – Represents a “sent” state in which code has called the XMLHttpRequest open() method and the XMLHttpRequest is ready to send a request to the server.

2 – Represents a “sent” state in which a request has been sent to the server with the send() method, but a response has not yet been received.

3 – Represents a “receiving” state in which the HTTP response headers have been received, but message body has not yet been completely received.

4 – Represents a “loaded” state in which the response has been completely received.

May 31, 2009

DOP Player WordPress Plugin

After several tests and favorable comments, I can officialy launch DOP Player WordPress Plugin 1.0.
Dop Player is intended for users that want an easy to use player to integrate in their blog.
Dop Player can be easily customized from an admin panel to match your template’s colors.

Warning
You have to copy the content from dop-player folder from the zip file. If you don’t you will see only a space where the player should be.
You have in the zip file:
- ZIP/dop-player/dop-player.php
- ZIP/dop-player/dop-player/dop-player-admin.php
- ZIP/dop-player/dop-player/dop-player.swf
In your plugin forlder you should have:
- WWW/wp-content/plugins/dop-player.php
- WWW/wp-content/plugins/dop-player/dop-player-admin.php
- WWW/wp-content/plugins/dop-player/dop-player.swf

You can download it from:
http://dop-p.com/wordpress/
http://wordpress.org/extend/plugins/dop-player/

An example

Admin Panel Screenshot
Admin Panel Screenshot