View Single Post
Old 28-06-2007, 05:33   #6 (permalink)
Naatan
Web Developer
 
Naatan's Avatar
 
Join Date: Jan 2007
Location: Brussels
Posts: 214
Send a message via MSN to Naatan
Some usefull functions there

Function to get the user IP, since one single technique doesn't always work

PHP Code:
function get_IP() {
    if (empty(
$_SERVER["HTTP_X_FORWARDED_FOR"])) {
        
$ip_address $_SERVER["REMOTE_ADDR"];
    } else {
        
$ip_address $_SERVER["HTTP_X_FORWARDED_FOR"];
    }
    if(
strpos($ip_address',') !== false) {
        
$ip_address explode(','$ip_address);
        
$ip_address $ip_address[0];
    }
    return 
$ip_address;


Or this one I got from another site, I don't remember where, it treats a string as if it is included by include();

Only downside is that you can't declare functions since it's already inside a function.

PHP Code:
function phpWrapper($content) {
    global 
$page;
    
ob_start();
    
$content str_replace('<'.'?php','<'.'?',$content);
    eval(
'?'.'>'.trim($content).'<'.'?');
    
$content ob_get_contents();
    
ob_end_clean();
    return 
$content;


Or a function to echo a string and immediatly echo it without delay

PHP Code:
function _echo($echo) {
    echo 
$echo;
    
flush();
    
ob_flush();


This one transforms a filename into a clean string, to be used as a title or whatever (for example, go_go_gadget.exe becomes "Go go gadget"

PHP Code:
function get_filetotitle($title) {
    
$title strip_path($title);
    
$title str_replace('_',' ',$title);
    
$title substr($title0strrpos($title'.'));
    
$bits explode(' ',$title);
    foreach (
$bits AS $bit) {
        
$return .= capitalize_firstchar($bit);
    }
    return 
$return;
}

function 
capitalize_firstchar($string) {
    return 
strtoupper(substr($string,0,1)).substr($string,1);

__________________
Developer of Divia CMS,
More info? Visit my blog.
  Reply With Quote