note 60279 added to function.str-replace
| From: | yaskulka | Date: | Sun, 01 Jan 2006 21:15:26 +0000 |
| Subject: | note 60279 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101087@lists.php.net to get a copy of this message | ||
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
?>
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60279
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60279&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60279&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60279&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60279&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60279&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60279&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60279&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60279&report=yes
Search -- http://master.php.net/manage/user-notes.php