note 60279 deleted from function.str-replace by aidan
| From: | aidan@php.net | Date: | Sun, 01 Jan 2006 21:55:05 +0000 |
| Subject: | note 60279 deleted from function.str-replace by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-101090@lists.php.net to get a copy of this message | ||
Note Submitter: yaskulka [at] gmail [dot] com
Reason: useless
----
You can use str_replace to find out TLD.
<?php
$ip_address = $_SERVER['REMOTE_ADDR'];
$hostname = gethostbyaddr ($ip_address);
$tld = str_replace (".","", strrchr ($hostname,"."));
echo $tld; //outputs tld that requested script
?>
This will print 'net', if request was made from www.hostname.net, 'com' if
requested from www.myip.com and so on. Useful in statistic collecting scripts. Also can be used to
find file extensions:
<?php
$filename = "mypicture.jpg";
$extension = str_replace (".","", strrchr ($filename,"."));
echo $extension; //outputs jpg
//for file with multiple extension
$filename2 = "mypicture.txt.jpg.zip.gif";
$extension = str_replace (".","", strrchr ($filename2,"."));
echo $extension; //outputs gif
?>