Ad Code

ID Your Body Using PHP

function generate_id($uri) {
    /* regular expressions */
    $regex1 = '/[^a-zA-Z0-9]/'; //remove anything but letters and numbers
    $regex2 = '/[\-]+/'; //remove multiple "-"'s in a row
    $regex3 = '/^[-]+/'; //remove starting "-"
    $regex4 = '/[-]+$/'; //remove ending "-"
    /* return... */
    return preg_replace(
                array($regex1,$regex2,$regex3,$regex4),
                array('-','-','',''),
                $_SERVER['REQUEST_URI']
              );
}

/* do it! */
$body_id = generate_id($_SERVER['REQUEST_URI']);


//assuming the page URI is:  /some-directory/deeper/my-page?category=mootools
$body_id = generate_id($_SERVER['REQUEST_URI']);


//returns:  some-directory-deeper-my-page-category-mootools
echo '<body id="',$body_id,'">';

 


 

Post a Comment

0 Comments