|
Quick Links |
Preview: Quick PHP Code Tips and Examples
![]() Quick PHP Code Tips and ExamplesPHP Programming Tips, Tutorials and Source Code Examples for newbie
Detect Alphabet only string with ctype_alpha Wed, 04 Jun 2008 20:07:20 PDT There are times when you need a function that can detect strings which contains onlyalphabetic characters. While is_numeric can validate a given string contains numeric character, there are no is_* function variation exist which can do the same for alphabetic strings. However, you can still test for alphabetic string using ctype_alpha() function. Example usage : PLAIN TEXT CODE: if [...]
How to Truncate table in SQLite database Wed, 04 Jun 2008 03:09:21 PDT I found out that truncating SQLite database is a little bit different from its MySQL counterpart. Here's how to truncate SQLite database from command line PLAIN TEXT CODE: sqlite your_database.db sqlite> DELETE FROM some_table; after that, dont forget to execute VACUUM to compact the database : PLAIN TEXT CODE: sqlite> VACUUM;
Quick PHP Code is back! Tue, 29 Apr 2008 21:25:53 PDT Quick PHP Code is back! So appology for the delays caused due to some unavoidable circumstances. We are no back!
How to solve file_get_contents and file() PHP errors Thu, 17 May 2007 18:47:03 PDT file_get_contents() is a function use to read an entire file to a string. It is occasionally use as a convenient function to retrieve web pages from remote servers in trivial PHP scripts. However, some web servers has disabled the URL retrieving capabilities in file_get_contents() function for security reasons, this caused scripts written with this function throws [...]
SQL Injection Examples (Cheatsheet) Wed, 16 May 2007 04:19:05 PDT If you're writing web application that has access to database, then you should be aware that those application are susceptible to SQL Injection attacks which leave information stored in your database vulnerable from a malicious cracker. This can led attacker to access private areas in your web application, steal sensitive information, erase your database or alter [...]
Naive Bayesian Tutorial in PHP Tue, 15 May 2007 21:45:18 PDT The practitioner of artificial intelligence and machine learning algorithm will recognize Naive Bayesian as one of the technique use to construct intelligent web application. Naive Bayesian is widely use as an intelligent classifier utilized to automatically classfies data based on statistical probability. Among the immediate use of Naive Bayesian technique is the classification of (spam) emails, [...]
Detect ip location, operating system and browser using PHP Detector Library Mon, 14 May 2007 19:40:17 PDT I've decided to share my PHP Detector library to the public which I've coded somewhere around 2006. The library does wonders in detecting IP address geo-location, operating system and the type of browser used based on its user-agent information. The ip address->geo-location information is provided for free from ShowIP fakap webservice. The library is handy for [...]
How to send e-mail with Attachment with PHP Scripts Mon, 14 May 2007 17:41:39 PDT Here's how to send an email with attachment using PHP scripts (via PHPMailer class). PLAIN TEXT CODE: require("phpmailer/class.phpmailer.php"); //**** //PLEASE CHANGE THE SETTINGS HERE !!!! //change settings here $your_email = "info@example.com"; $your_smtp = "mail.example.com"; $your_smtp_user = "info@example.com"; $your_smtp_pass = "example_password"; $your_website = "http://example.com"; //**** //get contact form details $name = $_POST['name']; $email = $_POST['email']; $url = $_POST['url']; $comments = $_POST['comments']; $response="Name: $name\nContents:\n$comments\n"; $mail = new PHPmailer(); $mail = $mail->SetLanguage("en", "phpmailer/language"); $mail->From = $your_email; $mail->FromName = $your_website; $mail->Host = [...]
PHP: Currency Exchange using XML-RPC client Thu, 10 May 2007 10:08:39 PDT This is an example PHP code I wrote to demonstrate how to connect to Foxrate Currency Exchange server and retrieve the latest exchange rate. The example uses The Incutio XML-RPC for PHP library. Please visit refer to Incutio XML-RPC Library Manual for further in-depth reference. PLAIN TEXT PHP: require('IXR.inc.php'); // connect to foxrate.org currency exchange server $client = new IXR_Client('http://foxrate.org/rpc/'); //make the [...]
OpenTracker - Lean and mean PHP Bittorrent Tracker Wed, 09 May 2007 20:48:06 PDT Opentracker is the most simple php bittorrent tracker that I came across. It only requires a single MySQL table to function and it is a fully compliant bittorrent tracker as outlined by Bram Cohen. I've included Opentracker in this blog because of its simplicity that made it easy to be use as a reference implementation for [...]
Spam Protected Contact Form example (using Akismet) Wed, 09 May 2007 03:07:44 PDT This is an example of an enhanced contact form previously featured here and here . I've improved the contact form example to include Akismet spam protection in order to make it more resistant to spam attack. Demonstration The example includes : PHPMailer class for sending mail through your own SMTP server Akismet Anti-spam class Table-less contact form Feel free to [...]
How to switch to PHP5 in Cpanel based web hosting Tue, 08 May 2007 09:33:27 PDT Some web hosting provider such as e-ruang offers choices of using PHP4 or or PHP5 in their hosting. To avoid conflict with existing scripts, they will usually offer PHP 4 by default. But for obvious reasons, you may want to use PHP5 as it supports more functionalities and more robust than PHP4. To enable PHP5 for [...]
Using SQLite in PHP 5 Tue, 08 May 2007 09:07:16 PDT Here is a well-written step-by-step tutorial on how to use SQLite in PHP 5. The tutorial was written by Ilia Alshanetsky and featured in Zend Developer Zone. SQLite Introduction For those who don't know, SQLite is a lightweight embedded database management system, it is available as the default database engine for PHP5. Due to its embedded nature, [...]
Truncate long text with PHP (excerpt function) Thu, 03 May 2007 09:36:31 PDT Truncate is a handy function which can truncate a long text into specific length string and adds elipsis (...) after it. This is an example of how the function "truncate($text,47)" works : Before PLAIN TEXT CODE: This is a very long text that I type as an example to show you the functionality of truncate After PLAIN TEXT CODE: This is a very [...]
PCRE Cheat Sheet (Perl Compatible Regular Expression) Thu, 03 May 2007 07:26:43 PDT Regular Expression (Regex, for short) is a very powerful feature in the PHP programming language. It is useful for manipulating strings using a set of well-defined rules. However the often complex syntax rules used in Regex can prove to be a challenge to some. Thankfully, the folks at PHPGure has produced a nice and [...] |
| ||||