View Single Post
Old 21-10-2007, 16:53   #21 (permalink)
KayGee
Registered User
 
Join Date: Oct 2007
Posts: 7
New to PHP...need help

Quote:
Originally Posted by 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);



It appears as though the PHP code above to transform a filename into a clean string is what I've been looking for. I'm on the ground floor with PHP, and without sounding like a complete idiot, I really need to know where this code goes and how to implement it on each of my web pages. I have a div for banner where I'd like the page title to appear. Do I simply place this code in the div?
  Reply With Quote