Recent Posts
thephpcode
Return To Blog Listing
thephpcode php code resource for all where we have code examples, cool techniques, tricks and sales of codes.
Recent Posts Tagged With 'php'
fontreplace - PHP/jQuery Font Replacement (FLIR)
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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)
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
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
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?
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
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?
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
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
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
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
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
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
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
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)
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
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...
