Hawkee

Hawkee

Joined
May 19, 2003
Occupation
Hawkee.com Admin
Location
Richmond
Website

PHP Code Snippets

Hawkee created a Page  -  Oct 31, 2014
1 306 

We now support CodePen embeds! While our page editor strips out most HTML tags, including <script> tags, we've made a special provision to support tags specifically from CodePen. All you need to do is paste the embed code directly from CodePen into the page editor.

 Respond   PHP  
Hawkee created a Page  -  Nov 04, 2012
405 

This will run nl2br on everything inside a string except for what is between the opening and closing tags. For example you can add 's to a comment that contains [ code ] tags without touching the code itself:

  4 Threads   PHP  
Hawkee created a Page  -  Jul 27, 2012
1,058 

This is a command line script that interfaces with Minecraft via rcon. It gives all the players on your server a chance to win a random item by typing "join". Here are the different modes:

  8 Threads   PHP  
Hawkee created a Page  -  May 15, 2012
1,174 

This is an easy to maintain method for creating clean urls without any file extensions. It's very good for hiding your underlying programming language and offers a more user friendly experience. It only uses a single series of mod_rewrite rules then all the rest of the logic can be accomplished within your script. You'll need mod_rewrite enabled and you can put these rules into your .htaccess or..

  3 Threads   PHP  
Hawkee created a Page  -  May 12, 2012

Ever wonder how many posts were made over the past few days or months? This is a very simple data visualization tool that shows you exactly how many.

 Respond   PHP  
Hawkee created a Page  -  Mar 02, 2012

This will take the date and time posted of an object in mySQL and convert it to a human readable form through PHP. It has 3 different modes of displaying the age:

  5 Threads   PHP  
Hawkee created a Page  -  Mar 21, 2011
5 771 

This function will return a list of page numbers similar to the Google search results style. It will currently show up to 15 page numbers at a time and this value can be adjusted within the function.

Hawkee created a Page  -  Jan 19, 2011

This will take a CSV file, create a table, and insert the data. The file needs to have a header row indicating the field names. Once it's created it uses a simple load data infile call.

  14 Threads   Shell   PHP  
Hawkee created a Page  -  Jan 21, 2009
1 502 

This is a very short and simple snippet that will take a given string, $string, and if it is plural the 's' will be removed from the $string.

  7 Threads   PHP  
Hawkee created a Page  -  Nov 19, 2008

This will extract the search query from a Google search. It doesn't specifically look for Google in the referer so it may capture more than just Google searches. You can use this information to re-perform the search on your own site or just keep it for your own records.

  4 Threads   PHP  
Hawkee created a Page  -  Mar 31, 2008

This is a little snippet that will remove any non-ASCII characters from a string.

  1 Thread   PHP  
Hawkee created a Page  -  Mar 24, 2008

This code produces a sort box for any number of arbitrary criteria on any type of data you have in your database. For this particular example we've got a product sort where users can sort by price or name.

  4 Threads   PHP  
Hawkee created a Page  -  Dec 10, 2007

This is a very simple PHP snippet that will set $title, $meta_keywords and $meta_description for use in your page header. You'll need to create meta_tags.txt which will use this format:

Hawkee created a Page  -  Jun 21, 2007

This will extract a zip file via PHP. Just be sure to set the $file and $path variables. $file represents the zip file name which may or may not contain a path. $path represents the directory to extract the files to. It will determine if the file is gz or zip and act accordingly. This uses the command line so be aware of the security risk.

  6 Threads   PHP  
Hawkee created a Page  -  Nov 18, 2005
18,277 

This will assign font sizes to tags based on their counts. It tries to evenly distribute the font sizes among the tags while keeping all tags with the same counts under the same font size. The data needs to be in the following format:

Hawkee created a Page  -  Nov 02, 2005

I thought this was pretty neat and useful. You can combine strtotime with the date function to create your own date verbally. This is just an alternative to using mktime that's a little more intuitive.

  3 Threads   PHP  
Hawkee created a Page  -  Mar 13, 2005

I've found this to be quite useful in handing uploaded files through HTTP. You can use this to move the file from your /tmp folder to a folder on your site that isn't mode 777. The concept is simple. It connects to your FTP server and puts the file in the folder of your choice. Usage:

  3 Threads   PHP  
Hawkee created a Page  -  Mar 10, 2005
3,328 

This will download a datafeed to your server from the given FTP account. This only supports CSV datafeeds and requires a minor tweak to accomodate any other type of datafeed. It also requires that you have wget installed on your server. The user executing this script needs to have write access to the "datafeeds" folder.

  4 Threads   PHP  
Hawkee created a Page  -  Sep 04, 2004

This is a ready to go PHP script that can be pasted into a blank .php document. Run it through your webserver after changing $myemail to the value of your E-Mail address. It also sends the referring URL to help you know where the visitor was before he clicked to contact you.

Hawkee created a Page  -  Aug 29, 2004

This is very handy for making a yyyymmddhhmmss date look pretty.

  3 Threads   PHP  
Hawkee created a Page  -  Aug 20, 2004

This generates two structures: a tree and a list of objects. Both are generated from the following standard parent/child database format:

Hawkee created a Page  -  Aug 12, 2004
6,888 

I use this almost every day. It's one of the most useful PHP debugging tools. You can print all of the contents of a variable (class, array or scalar) to get an idea of how the structure looks.

  2 Threads   PHP  
Hawkee created a Page  -  Aug 11, 2004
12,619 

This will convert a sortable YYYY-MM-DD date into a more presentable date. $date can be set to any date as long as it fits this format.

  3 Threads   PHP  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.