How to get file extensions in PHP

21 May 2009 In: PHP

There are several methods get a file extension using PHP:

<?
$filename = 'myfile.jpg';
 
// 1. The "explode/end" method
$ext = end(explode('.', $filename));
 
// 2. The "strrchr" method
$ext = substr(strrchr($filename, '.'), 1);
 
// 3. The "strrpos" method
$ext = substr($filename, strrpos($filename, '.') + 1);
 
// 4. The "preg_replace" method
$ext = preg_replace('/^.*\.([^.]+)$/D', '$1', $filename);
 
// 5. The "never use this" method
//   From: http://php.about.com/od/finishedphp1/qt/file_ext_PHP.htm
$exts = split("[/\\.]", $filename);
$n = count($exts)-1;
$ext = $exts[$n];
?>

Free premium wordpress themes

20 May 2009 In: Bookmarks

High quality free Wordpress Themes have become harder and harder to find in the past year, with the influx of premium themes, more and more designers and developers are selling themes (and rightly so, they do amazing work). But, that aside, the quality is certainly there, and we are sure you will be impressed with this Wordpress theme compilation for 2009.

1 – Blog & Portfolio Themes(1-35)

2 – Magazine & Corporate Themes(36-57)

3 – Photo blogs & Gallery Themes(58-68)

4 – Minimal & Clean Themes Themes(69-84)

5 – Smashing Magazine Themes(85-98)

6 – Something different… (99-104)

Blog & Portfolio Themes

One Room [Demo]

Free Wordpress themes

Elegant Grunge [Demo]

Free Wordpress themes

Fusion [Demo] Read the rest of this entry »

Debian: How to make scripts run at boot

17 May 2009 In: Linux

Debian uses a Sys-V like init system for executing commands when the system runlevel changes – for example at bootup and shutdown time.

If you wish to add a new service to start when the machine boots you should add the script to the directory /etc/init.d/. Many of the scripts already present in that directory will give you an example of the kind of things that you can do.

Here’s a very simple script which is divided into two parts, code which always runs, and code which runs when called with “start” or “stop”. Read the rest of this entry »

I spend a lot of time lurking in the channel # PHP (EFnet and freenode, please – no flame wars) and this issue is a frequently asked that the rule is a simple answer in the form of the use of strpos (), or best to ip2long () in a more than less than reply.

Unfortunately, although the people in the rule that an IP address is just an unsigned 32-bit integer, and is easy to determine, usually with $ _SERVER [ "REMOTE_ADDR"], where the real challenge – is in defining the range within which it must decide whether the IP address. IP ranges are usually divided into three categories (in increasing complexity):

1. Wild Card: 192.168.10 .*
2. Start-end: 10.1.0.0-10.1.255.255
3. * CIDR: 172.16.1.0/24

* Classless Inter-Domain Routing
Read the rest of this entry »

Quick sort for associative arrays

16 May 2009 In: Algorithm, Off Topic, PHP

Here is the way of quick sort in associative arrays;

<? 
 
function qsort($a,$f) { 
       qsort_do(&$a,0,Count($a)-1,$f); 
} 
 
function qsort_do($a,$l,$r,$f) { 
       if ($l < $r) { 
               qsort_partition(&$a,$l,$r,&$lp,&$rp,$f); 
               qsort_do(&$a,$l,$lp,$f); 
               qsort_do(&$a,$rp,$r,$f); 
       } 
} 
 
function qsort_partition($a,$l,$r,$lp,$rp,$f) { 
       $i = $l+1; 
       $j = $l+1; 
 
       while ($j <= $r) { 
               if ($f($a[$j],$a[$l])) { 
                       $tmp = $a[$j]; 
                       $a[$j] = $a[$i]; 
                       $a[$i] = $tmp; 
                       $i++; 
               } 
               $j++; 
       } 
 
       $x = $a[$l]; 
       $a[$l] = $a[$i-1]; 
       $a[$i-1] = $x; 
 
       $lp = $i - 2; 
       $rp = $i; 
} 
 
?>

PHP Optimizing Tips

14 May 2009 In: PHP

Here is the list of 43 short tips you can use for writing an optimized and more efficient PHP code:

1. If a method can be static, declare it static. Speed improvement is by a factor of 4.
2. echo is faster than print.
3. Use echo’s multiple parameters instead of string concatenation.
4. Set the maxvalue for your for-loops before and not in the loop.
5. Unset your variables to free memory, especially large arrays.
6. Avoid magic like __get, __set, __autoload
7. require_once() is expensive Read the rest of this entry »

Searching strings in a multi-dimensional array

12 May 2009 In: PHP

I’m working on a security and trying to make searches in a multi-dimensional array
Here is the function;

<?php
function multi_array_search($needle, $haystack, $key, &$result, $searchlevel = 0) { 
  while(is_array($haystack) && isset($haystack[key($haystack)])) {
    if($searchlevel == 0 && key($haystack) == $key && $haystack[$key] == $needle) {
      $result = $haystack;
    } elseif($searchlevel > 0) {
      multi_array_search($needle, $haystack[key($haystack)], $key, $result, $searchlevel - 1);
    }
    next($haystack);
  }
}
?>

Example;
2-dimensional array, search by both key and value
$arr1 = array(
1 => array(‘id’ => 1, ‘name’ => ‘Ersin’, ‘gender’ => ‘male’),

12 => array(‘id’ => 12, ‘name’ => ‘Emel’, ‘gender’ => ‘female’),
);

<?php array_search_in_level('Emel', $arr1, 'name', $result, 1); ?>

$result is:
array(
‘id’ => int 12
‘name’ => string ‘Emel’ (length=4)
‘gender’ => string ‘female’ (length=4)
)

Free CSS Themes

12 May 2009 In: Bookmarks, CSS

I made a quick list for Free CSS theme sites.
Here is the list;

http://www.freecsstemplates.org/css-templates/

http://www.free-css-templates.com/

http://www.freecsstemplates.org/

http://csscreme.com/freecsstemplates/

http://www.templatemo.com/

http://www.solucija.com/free-templates

Introduction

The following HOWTO will show you exactly how to install the following packages on a Debian Etch or Ubuntu 7.06 system:

  • FFmpeg
  • FFmpeg-PHP
  • Mplayer + Mencoder
  • flv2tool
  • LAME MP3 Encoder
  • AMR (for 3gp file conversions)
  • Libogg
  • Libvorbis

Read the rest of this entry »

How to change language of Debian

7 May 2009 In: Linux

Hi,
İf you want to change debian’s system language you must follow these steps;

sudo apt-get update
sudo apt-get install debconf
sudo dpkg-reconfigure locales

Or you could add something like the following lines to /etc/environment

LANG=”en_US.UTF-8″
LANGUAGE=”en_US:en”

If you want different locales for different users, you can add that to their
.bashrc files

Here’s some links that touch on what you’re looking for:

http://gallery.menalto.com/wiki/Debian_locale_HowTo

http://melkor.dnp.fmph.uniba.sk/~garabik/debian-utf8/howto.html


Sponsors

1. http://abell.as.arizona.edu/~hill/cgi-bin/webglimpse.cgi/home/hill/public_html/4x4?query=%22%3E%3Ca+href%3Dhttp%3A%2F%2Fwww.rollondoc.com%3ELink%3C%2Fa%3E&errors=0&age=&maxfiles=50&maxlines=30&cache=yes 2. http://aboutdomain.org/info/www.rollondoc.com/ 3. http://aboutus.org/www.rollondoc.com 4. http://alexa.com/siteinfo/www.rollondoc.com 5. http://backlinkcheck.com/popular.pl?url1=www.rollondoc.com&cache=yes 6. http://backtype.com/url/www.rollondoc.com&cache=yes 7. http://browsershots.org/http://www.rollondoc.com 8. http://builtwith.com/?www.rollondoc.com 9. http://checkdomain.com/cgi-bin/checkdomain.pl?domain=www.rollondoc.com&cache=yes 10. http://childstats.gov/disclaim.asp?URL=http://www.www.rollondoc.com&cache=yes 11. http://ciac.llnl.gov/cgi-bin/webglimpse/www/htdocs/ciac/archive?query=%22%3E%3Ca+href%3Dhttp%3A%2F%2Fwww.rollondoc.com%3ELinks%3C%2Fa%3E&errors=0&age=&maxfiles=50&maxlines=30&cache=yes 12. http://cnm.edu/extlink.php?link=http://www.rollondoc.com 13. http://cqcounter.com/rbl_check/?query=www.rollondoc.com&cache=yes 14. http://cqcounter.com/siteinfo/?query=www.rollondoc.com&cache=yes 15. http://cqcounter.com/traceroute/?query=www.rollondoc.com&cache=yes 16. http://cubestat.com/www.rollondoc.com&cache=yes 17. http://democrats.assembly.ca.gov/members/scripts/redirect.asp?url=http://www.rollondoc.com&cache=yes 18. http://domains.whois.com/domain.php?action=whois&query=www.rollondoc.com 19. http://esitestats.com/www.rollondoc.com&cache=yes 20. http://export.gov/wcm/fragments/fl_eg_outsidelinks/redirect.asp?URL=http://www.rollondoc.com&cache=yes 21. http://www.fairfaxcounty.gov/offsite/?pg=http://www.rollondoc.com 22. http://www.fbi.gov/cgi-bin/outside.cgi?http://www.rollondoc.com 23. http://www.fcc.gov/fcc-bin/bye?http://www.rollondoc.com 24. http://feedest.com/feedHost.cfm/host/www.rollondoc.com&cache=yes 25. http://find-ip-address.org/whois/mrwhois_details.php?ddomain=www.rollondoc.com&server=whois.opensrs.net 26. http://www.fmc.gov/home/offsite.asp?URL=http://www.rollondoc.com&cache=yes 27. http://grader.com/site.php?URL=www.rollondoc.com&cache=yes 28. http://home.nps.gov/applications/redirect/?sUrl=http://www.rollondoc.com 29. http://hosts-file.net/?s=www.rollondoc.com&cache=yes 30. http://ip-adress.com/whois/www.rollondoc.com&cache=yes 31. http://iwebtool.com/pagerank_checker?domain=www.rollondoc.com 32. http://marad.dot.gov/exit.asp?type=1&url=www.rollondoc.com&cache=yes 33. http://markosweb.com/www/www.rollondoc.com/ 34. http://milonic.com/whois.php?domain=www.rollondoc.com&ref=&WebServer= 35. http://www.minfin.gov.by/search/?action=index&text=%22%22%3E%3Ca+href%3Dhttp%3A%2F%2Fwww.rollondoc.com%2F%3ELink%3C%2Fa%3E%3C%22 36. http://namedroppers.com/who/www.rollondoc.com 37. http://ncsacw.samhsa.gov/offsite.asp?url=http://www.rollondoc.com&cache=yes 38. http://netvaluer.com/show.asp?site=www.rollondoc.com&cache=yes 39. http://networksolutions.com/whois-search/www.rollondoc.com&cache=yes 40. http://network-tools.com/default.asp?prog=whois&host=www.rollondoc.com&cache=yes 41. http://nws.noaa.gov/cgi-bin/nwsexit.pl?url=http://www.rollondoc.com&cache=yes 42. http://nsf.gov/cgi-bin/good-bye?http://www.rollondoc.com 43. http://nps.gov/cgi-bin/intercept?http://www.rollondoc.com 44. http://opic.gov/leaving.asp?url=http://www.rollondoc.com&cache=yes 45. http://oceanservice.noaa.gov/cgi-bin/redirout.cgi?url=http://www.rollondoc.com&cache=yes 46. http://page2rss.com/page?url=www.rollondoc.com/ 47. http://pageheat.com/heat/www.rollondoc.com 48. http://protect-x.com/info/www.rollondoc.com&cache=yes 49. http://quantcast.com/www.rollondoc.com 50. http://quantcast.com/profile/no-data-for-site?domain=www.rollondoc.com&cache=yes 51. http://quarkbase.com/show/www.rollondoc.com 52. http://quest.nasa.gov/cgi-bin/glimpse2/webglimpse.cgi?ID=1&cache=yes&query=%22%3E%3Ca+href%3Dhttp%3A%2F%2Fwww.rollondoc.com%3Links%3C%2Fa%3E&errors=0&age=&maxfiles=50&maxlines=30&cache=yes 53. http://ratite.com//whois/whois.cgi?domain=www.rollondoc.com&cache=yes 54. http://registrar.verisign-grs.com/cgi-bin/whois?whois_nic=www.rollondoc.com&x=60&y=12&type=domain&cache=yes 55. http://rehab.alabama.gov/Home/Misc/Redirect.aspx?url=http://www.rollondoc.com&cache=yes 56. http://ram3.chem.sunysb.edu/cgi-bin/webglimpse.cgi?ID=2&query=%22%3E%3Ca+href%3Dhttp%3A%2F%2Fwww.rollondoc.com%3ELinks%3C%2Fa%3E&rankby=DEFAULT&errors=0&age=&maxfiles=20&maxlines=10&maxchars=2000&cache=yes 57. http://reports.internic.net/cgi/whois?whois_nic=www.rollondoc.com&type=domain&cache=yes 58. http://robotics.nasa.gov/rcc/redirect.php?url=%2F%2Fwww.rollondoc.com&cache=yes 59. http://roc.noaa.gov/scripts/exit/osfexit.pl?url=http://www.rollondoc.com&cache=yes 60. http://robtex.com/dns/www.rollondoc.com.html 61. http://seoarena.org/sh/www.rollondoc.com/ 62. http://siteadvisor.cn/sites/www.rollondoc.com/summary/&cache=yes 63. http://siteadvisor.cn/sites/www.rollondoc.com 64. http://siteanalytics.compete.com/www.rollondoc.com 65. http://sitedossier.com/site/www.rollondoc.com&cache=yes 66. http://sitetiki.com/www.rollondoc.com&cache=yes 67. http://snapnames.com/?aff=321&dom=www.rollondoc.com&cache=yes 68. http://spacereg.com/a.rpl?m=whois&domain=www.rollondoc.com&cache=yes 69. http://statbrain.com/www.rollondoc.com&cache=yes 70. http://statsaholic.com/www.rollondoc.com&cache=yes 71. http://tampafl.gov/common/redirect.asp?redirect=www.rollondoc.com/&cache=yes 72. http://tgsc.ru/redirect/http://www.rollondoc.com&cache=yes 73. http://toolbar.netcraft.com/site_report?url=http://www.rollondoc.com&cache=yes 74. http://www.transtats.bts.gov/exit.asp?url=http://www.rollondoc.com&cache=yes 75. http://tweetmeme.com/domain/www.rollondoc.com 76. http://uk1.co.uk/cgi-bin/cart/cart.cgi?typeofsearch=rawwhois&domain=www.rollondoc.com&server=whois.nic.uk&cache=yes 77. http://uptime.netcraft.com/up/graph?site=www.rollondoc.com&cache=yes 78. http://urladex.com/index.py?page=url&url=www.rollondoc.com&cache=yes 79. http://urltrends.com/viewtrend.php?url=www.rollondoc.com&cache=yes 80. http://websiteaccountant.com/www.rollondoc.com&cache=yes 81. http://websiteoutlook.com/www.www.rollondoc.com&cache=yes 82. http://whois.webhosting.info/www.rollondoc.com 83. http://www.weather.gov/cgi-bin/nwsexit.pl?url=http://www.rollondoc.com&cache=yes 84. http://whatismyip.com.np/whois.php?query=www.rollondoc.com&cache=yes 85. https://who.securepaynet.net/whoischeck.aspx?ci=14582&domain=www.rollondoc.com&prog_id=enet_world&cache=yes 86. http://who.godaddy.com/whoischeck.aspx?Domain=www.rollondoc.com&cache=yes 87. http://who.is/whois/www.rollondoc.com/&cache=yes 88. http://whois.domainpeople.com/whois.cgi?domain=www.rollondoc.com&cache=yes 89. http://whois.domaintools.com/www.rollondoc.com&cache=yes 90. http://whois.net/whois/www.rollondoc.com&cache=yes 91. http://whois.tools4noobs.com/info/www.rollondoc.com&cache=yes 92. http://whoisbeta.com/index.php?query=www.rollondoc.com&cache=yes 93. http://whoisbucket.com/view/www.rollondoc.com&cache=yes 94. http://whoisd.com/search.php?code=2119&domain=www.rollondoc.com&GO=GO 95. http://whoisn.com/lookup.php?domain=www.rollondoc.com&button1=Check&cache=yes 96. http://whois-search.com/whois/www.rollondoc.com&cache=yes 97. http://whoisx.co.uk/www.rollondoc.com&cache=yes 98. http://whoisya.com/www.rollondoc.com&cache=yes 99. http://workforcesecurity.doleta.gov/foreign/redirect.asp?link=www.rollondoc.com/&cache=yes 100. http://www2.scc.rutgers.edu/ead/showfile.php?filename=http://www.rollondoc.com&cache=yes 101. http://www3.mt.gov.br/redirect.php?url=//www.rollondoc.com/&cache=yes 102. http://www-nrd.nhtsa.dot.gov/utility/direct.asp?url=http://www.rollondoc.com&cache=yes 103. http://xmarks.com/site/www.rollondoc.com/&cache=yes 104. http://zoneedit.com/whois.html?zone=www.rollondoc.com&cache=yes