Recent Posts

thephpcode

thephpcode

Return To Blog Listing

thephpcode php code resource for all where we have code examples, cool techniques, tricks and sales of codes.

Search This Blog's Tags For:

Recent Posts Tagged With 'php'

  • fontreplace - PHP/jQuery Font Replacement (FLIR)

    Posted on Thursday December 31st, 2009 at 00:53 in php, javascript, download, replacement, font, jquery

    Lately I was quite into web design and interface so much that I started exploring sIFR and FLIR. Yesterday I decided to develop a FLIR for PHP and jQuery.You can download the fontreplace package at: http://www.mediafire.com/?0o511knwywm (122 kB, zip ...

  • jQuery-like chaining in PHP\'s Object Oriented Programming

    Posted on Friday October 30th, 2009 at 11:14 in php, javascript, oop, class, chain, jquery

    It's interesting to see how object methods in PHP can be chained just like jQuery's chaining. jQuery's chaining:$("div").children(".firstbtn").hide().fadeIn();In PHP, it is also possible to chain similarly. Using the string class from Samstyle PHP Fr...

  • file_get_contents() vs fread() - Speed Test and Benchmarking

    Posted on Sunday October 11th, 2009 at 21:50 in php, speed, code, data, files, functions, optimize

    File access is commonly found in any PHP application. Be it caching, or reading data from a file or what. Lately I've been wondering, whether the use of file_get_contents() over fread() is a good practice (i always prefer file_get_contents()).So this...

  • Using Bit Shifting to Divide / Multiply

    Posted on Saturday October 10th, 2009 at 04:25 in php, code, optimize, bits

    To think of it, I rarely use bitwise operators in my coding - especially with all the convenience of other operators (can you imagine calculating bits whole day?).But seriously when I was reading on Bitwise operators, I realised that ($n / 2) == ($n ...

  • Pre vs Post Increment in PHP

    Posted on Saturday October 10th, 2009 at 04:14 in php, code, optimize, loop, iteration

    Earlier on I was browsing Google Code, and I chanced upon JSpeed - a javascript optimizer. I saw that they actually change post increments to pre-increments. I wondered why and thought I could ask this on Stack Overflow.One theory came up to be "prei...

  • Session Denial: session id contains illegal characters

    Posted on Tuesday September 22nd, 2009 at 21:23 in php, Security, cookie, session

    This morning I woke up, went over to StackOverflow (Yes I admit lately I've been quite active answering questions on SO) and I saw this question: Session hijacking or attack?The asker, Toto, saw these in his error logs:[22-Sep-2009 21:13:52] PHP Warn...

  • PHP speed up: Quote your strings

    Posted on Friday September 4th, 2009 at 09:47 in php, speed, code, statement, variable, string, constant, example

    I've wanted to post this earlier, but i've been busy lately. So yeah, here's a tip off on how to speed things up for new or beginner php developers.You might have noticed, PHP error level by default is set to E_ALL & ~E_NOTICE, which means all errors...

  • PHP GD: allow PHP to decide image type

    Posted on Monday August 31st, 2009 at 09:42 in php, code, gd, example

    It is at times quite troublesome having the need to detect what image type is the file, then decide which function (imagecreatefromjpeg, imagecreatefrompng or imagecreatefromgif) to use for the image. Well, here's a simple solution.<?php$src = "ht...

  • PHP new development site/manual

    Posted on Thursday August 27th, 2009 at 10:40 in php, website

    I was browsing the web earlier on, and I chanced upon one of the PHP website development server at http://pb11.php.net/Some comments:the interface (UI) is definitely much better and everything's clearer.however, the layout and contents are much about...

  • Calculating Age using Birthday in PHP

    Posted on Thursday August 6th, 2009 at 18:22 in php, code, Projects, function, calculations

    Here's some food for the thoughts: calculating age using birthday in PHP. <?phpfunction getAge($birthday){ $dt = strtotime($birthday); // convert the birthday to a standard format (UNIX epoch) $a = gmdate('Y') - gmdate('Y',$dt); // find th...

  • Calling PHP functions from Javascript using/via AJAX

    Posted on Thursday July 30th, 2009 at 00:37 in php, asp, Ajax, functions

    This has been quite a topic for some time - the ability for PHP functions to be called from Javascript. Well, yesterday I did it by implementing this feature into Samstyle PHP Framework. This is similar to ASP.NET AJAX Extension's Webservice, where y...

  • PHP: Generate random color code

    Posted on Saturday July 25th, 2009 at 22:37 in php, Color, code, gd

    Hello! today I was surfing the net again reading up articles when I came across this website which has a few codes on several uses. but their snippets were quite full of flaws and vulnerability.well, I am going to talk about one of their code snippet...

  • Using single instead of double quotes in PHP

    Posted on Thursday July 23rd, 2009 at 09:49 in php, quotes, speed, script, string, declaration

    Today I was reading up on some articles on the web when I suddenly gave thought about the codes I have always been doing.The other day I was talking to my friend about using single or double quotes, and I persisted on using single quotes instead of d...

  • Samstyle PHP Framework v1.2.0 released

    Posted on Monday July 20th, 2009 at 10:46 in php, html, javascript, library, applications, http, framework

    Finally Samstyle PHP Framework v1.2.0 is released! As promised, most features listed on the project home page are implemented in the v1.2.0 release.You can download a copy of the framework and start using it by visiting the project home page at http:...

  • PHP GD: Creating a security captcha in PHP

    Posted on Tuesday July 14th, 2009 at 02:57 in php, Security, guide, images, hash, captcha, gd

    I was working on an application yesterday when I had to write a captcha security check on the form. So I came up with the following script to generate an image with random code. The script will also rotate the code a little in the image and randomize...

  • Microsoft with PHP (on Windows IIS 7)

    Posted on Sunday July 5th, 2009 at 04:19 in php, asp, windows, Microsoft, iis

    If you're thinking whether deploying PHP applications on your IIS or Windows Servers is possible - the answer is Yes.Lately Microsoft have shown their support for PHP through IIS 7 on their website (http://www.microsoft.com/windowsserver/compare/php-...

  • Using include() in caching

    Posted on Saturday July 4th, 2009 at 11:22 in php, tips, Security, code, hacker, dynamic, load, cache, buffer

    Caching in a dynamically generated website is a great trick to speed things up. Can you imagine if 5000 users come to your web page at the same time, and you have to grab data from the database, manipulate, validate then output the data 5000 times? ...

  • Samstyle PHP Framework

    Posted on Friday July 3rd, 2009 at 19:29 in php, framework

    Hi all!I am opening my framework to be open source. More details of it can be found at http://code.google.com/p/samstyle-php-framework/.The framework aims to be the fastest, easiest, scalable, easily deployable and most expandable framework for PHP t...

  • PHP Functions - too dynamic?

    Posted on Friday July 3rd, 2009 at 04:12 in php, dynamic, functions, declaration

    Today I was working on an application, where I found it strange when my application function is not working as I wanted it to be.After a quick debug, I found out that it's because:func($param1,$param2,$param3); // the way i am calling the functionfun...

  • Enabling extensions/dll in PHP of XAMPP

    Posted on Friday July 3rd, 2009 at 04:00 in php, library, extensions, hash, curl, xampp, dll, apache friends, php.ini

    It has become common that as we work on our application locally, we might need to enable more and more extensions. For example, cURL and hash, they are not enabled on XAMPP's PHP by default. To enable the dynamic extensions you need in PHP, simply go...

  • Array vs Class - which is better?

    Posted on Thursday July 2nd, 2009 at 09:43 in php, memory, methods, array, class, benchmark, foreach

    The other day I was discussing with my friend and we talked about Array and Classes. of course in Samstyle PHP Framework, I actually dropped the usage of classes. There are reasons why I went for arrays instead of classes.With the help of PHP: Arrays...

  • Image Comparison Tool

    Posted on Tuesday June 23rd, 2009 at 03:05 in php, windows, download, script, tool, console, gd, php2bin, bamcompiler, php2exe

    Remember the Image Comparison script i had mentioned earlier on? I have compiled it into a Windows console application. Check it out belowUsage: imgcmp image1.ext image2.extCheers to all! It will return in percentage as output on the console....

  • PHP GD: Getting pixel information

    Posted on Sunday June 21st, 2009 at 06:17 in php, Color, library, images, code, bits, gd

    Hello there! It's Sam Yong here again. Earlier on I was developing a PHP script for comparing 2 images and find out their similarity. I was rather successful with it.Well, today I am going to discuss about PHP's GD library - how to get the Red, Green...

  • Variable Variables

    Posted on Friday June 19th, 2009 at 01:28 in php, variable

    Have you really thought about how dynamic PHP can be? Well seriously if you haven't, check this out! Variable variables.<?php$a = 'hello';$hello = 'hello world!';echo $$a;// outputs as "hello world!"?>Why? $$a is evaluated automatically by PHP ...

  • Setting up local Mail (SMTP, POP3, IMAP) Server on XAMPP

    Posted on Wednesday March 25th, 2009 at 18:34 in php, mail, server, pop3, smtp, imap, xampp, hmailserver

    While I was doing a PHP project on my localhost using XAMPP, i realised I needed a local mail server in order to send out mails from my own workstation for testing. To come to think of it, XAMPP provides MercuryMail - but it's user-unfriendly interfa...

  • PHP Output Buffering

    Posted on Saturday February 14th, 2009 at 18:10 in php, tips, script, variable, string, output, programmer, function, buffer

    wow, it's been awhile already but i'm back to post more PHP-related articles. lately i'm busy working on another project for Microsoft Imagine Cup - the round 1 ends on 27 Feb 09. Normally when most PHP programmers codes their PHP application, they'l...

  • Trimming each line: trim() function

    Posted on Tuesday February 3rd, 2009 at 08:07 in php, string, trim, function, multiline

    Just a few days ago, i ran into this problem of needing to trim off spaces in front and behind of each line of a string with multiline. so i came up with this simple function to do the job.function trimlines($s,$t){$e = explode("\n",$s);foreach($e as...

  • PHP: Getting Secondary Internet Protocol (IP) Address

    Posted on Tuesday January 13th, 2009 at 03:29 in php, http, ip address, pastebin

    You'll probably get the Remote IP Address of your users by using the server variable $_SERVER['REMOTE_ADDR']. However, if your users are being proxy servers or using dynamic IP address, you won't get the actual IP Address of your users using $_SERVER...

  • Cleaning/Stripping/Removing empty lines using PHP Regex (Regular Expressions)

    Posted on Friday January 9th, 2009 at 20:07 in php, html, css, javascript, code, function, regex, pcre

    Removing empty lines from whole chunk of HTML/CSS/Javascript output would do great effects. With the function below which uses preg_replace (Perl-Compatible Regular Expressions - PCRE Regex), you can easily strip off empty lines, which can improve yo...

  • Why exit(); after Header redirect

    Posted on Saturday January 3rd, 2009 at 21:37 in php, header, exit, redirect, example

    You'll probably need a few HTTP 302 or 301 redirect in your PHP application when you develop it. To do a redirect, you can easily call:if(!$valid){header('Location: nextpage.php');}unlink('tmp/2A4E22F1.dat');However, many people do not know that even...