background preloader

PHP Tutorials and Reference Guide

PHP Tutorials and Reference Guide

15 very useful PHP code snippets for PHP developers | ViralPatel.net Following are list of 15 most useful PHP code snippets that a PHP developer will need at any point in his career. Few of the snippets are shared from my projects and few are taken from useful php websites from internet. You may also want to comment on any of the code or also you can share your code snippet through comment section if you think it may be useful for others. 1. Send Mail using mail function in PHP 2. 3. The above code will not work in case your client is behind proxy server. 4. This function will return the duration of the given time period in days, hours, minutes and seconds. e.g. secsToStr(1234567) would return “14 days, 6 hours, 56 minutes, 7 seconds” 5. 6. Required Extension: SimpleXML 7. 8. Following is the PHP code to create the JSON data format of above example using array of PHP. Following code will parse the JSON data into PHP arrays. 9. 10. This basic snippet will create a random authentication code, or just a random string. 11. Validate a date in “YYYY-MM-DD” format.

Perl By Sam Hughes Perl is a dynamic, dynamically-typed, high-level, scripting (interpreted) language most comparable with PHP and Python. Perl's syntax owes a lot to ancient shell scripting tools, and it is famed for its overuse of confusing symbols, the majority of which are impossible to Google for. Perl has horrors, but it also has some great redeeming features. This document is intended to be informative, not evangelical. dislike the official Perl documentation at for being intensely technical and giving far too much space to very unusual edge cases learn new programming languages most quickly by "axiom and example" wish Larry Wall would get to the point already know how to program in general terms don't care about Perl beyond what's necessary to get the job done. This document is intended to be as short as possible, but no shorter. Preliminary notes Hello world A Perl script is a text file with the extension .pl. Here's the full text of helloworld.pl: A few immediate notes.

7 Secure, Lightweight, and Easy to Use PHP Frameworks Choosing a good PHP frameworks can help you develop complex Rich Internet Applications quickly, with a best practices oriented approach, and saving a lot of time reusing code snippets that are already available. There are a lot of interesting PHP frameworks you can choose for your next web project. Which framework you choose is really a personal decision. There is no one “best” framework on the market at the moment. Different frameworks are better for different types of projects, and for different developer. Today we will focus on 7 secure, lightweight and easy to use PHP Frameworks. Why Use a PHP Framework? There are plenty of reasons to use a PHP Framework to build your websites. 1. Below we’ve covered some of the best frameworks available today. 1. CodeIgniter is a powerful, high-performance, open-source PHP framework that helps you author PHP applications rapidly. CodeIgniter has an exciting online manual, a couple of helpful video tutorials and an active user forum. 2. 3. 4. 5. 6. 7.

21 Things You Must Know About CakePHP Original >> Easily creating static pages I needed to create several pages that didn't use any models and contained static data inside the default layout. My first thought was to create a controller for these pages and define an action for each static page I needed. However, this solution seemed tedious and would make it difficult to quickly add new pages. Static pages - Adjusting the page title If you're using the pages controller and you need to change the page title, add the following to your view: <? Static pages - Adjusting other data sent to the layout If you need to send data to the layout (such as a variable indicating what section to highlight on the nav bar), add this to your view: <? That array should then be accessible as $somedata inside your layout. Creating a simple admin center Viewing the SQL queries that are running behind the scenes Multiple sources of documentation Don't just rely on the manual. Using bake.php Mind permissions when moving cake around Complex model validation

pChart | a PHP Charting library 10 code snippets for PHP developers « The html blog I’ve compiled a small list of some useful code snippets which might help you when writing your PHP scripts… Email address check Checks for a valid email address using the php-email-address-validation class. Source and docs: 01.include('EmailAddressValidator.php'); 03. 04.if ($validator->check_email_address('test@example.org')) { 07.else { Random password generator PHP password generator is a complete, working random password generation function for PHP. 01.function generatePassword($length=9, $strength=0) { 02. 03. 04. if ($strength & 1) { 05. 07. if ($strength & 2) { 08. 10. if ($strength & 4) { 11. 13. if ($strength & 8) { 14. 17. 18. 19. for ($i = 0; $i < $length; $i++) { 20. if ($alt == 1) { 21. 22. 23. } else { 24. 25. 28. return $password; Get IP address Returns the real IP address of a visitor, even when connecting via a proxy. 01.function getRealIpAddr(){ 02. if (! 04. 06. elseif (! 08. 10. else{ 11. 13. return $ip; XSL transformation 01. 04. 05. 08.

Killer Game Programming in Java Killer Game Programming in Java is for people who already know the basics of Java. For example, students who've finished an 'Introduction to Java' course. The aim is to teach reusable techniques which can be pieced together to make lots of different, fun games. For example, how to make a particle system, first-person keyboard controls, a terrain follower, etc. If you don't know Java, then Killer Game Programming in Java isn't for you. The main emphasis of my book (over 17 chapters) is on 3D gaming using Java 3D. Early (sometimes very early) draft versions of the book's chapters can be downloaded from here (see the links below). All the book's code is here, either downloadable as a single zip file (visit the code page), or on a chapter-by-chapter basis from each chapter's page (see the links below). I've also been adding new chapters here; chapters which don't appear in the book. There's a Czech edition of my book. So now I'm an expert author: (not a) Eight Step Plan to Publishing Greatness.

Ten PHP Best Practices Tips that will get you a job | PHP vs .Net Posted by blake on Jun 4, 2008 in Code, Performance, PHP | 167 comments The last couple of weeks have been quite the experience for me. I was part of a big layoff at my former company, which was interesting. I've never been in that position before, and it's hard not to take it personally. I started watching the job boards, and a nice-looking full-time PHP position caught my eye, so I sent out a resume and landed an interview. Find the errors in the following code: So, give it a shot. If you got the missing comma in the parameter list, the "new Array()" error, the colon instead of a semi-colon, the '=' instead of '=>' in the foreach statement, and the erroneous use of '+' on the echo line, then congratulations, you found all the errors! That's not how I answered the question though. After pointing out the actual errors, I made a point of adding comments about those things I just mentioned. So, read on for my Ten PHP Best Practices Tips that will get you a job: 1. 2. 3. 4. 5. 6. 7. 8. 9.

PHP Tutorial Simple Layouts with PHP This tutorial is for those starting out in PHP and want to learn a great way to create layouts. This will help reduce redundancy and keep you from writing too much code. Download the Source Anyone that has been developing HTML based sites for some time has undoubtedly ran in to the issue of keeping the design consistent across multiple pages. Technique #1 A lot of sites follow this kind of layout scheme The first technique is the entry level solution that works across nearly all situations. <! Take out everything up to the point and put that in a new file called head.php. <? Now just put whatever HTML/PHP content you want in between those two include statements and check it out in a browser. It may be easier to think of it as a puzzle, you are piecing together a complete HTML page with includes. Technique #2 Alright we have that under our belt let’s look at another solution. <! This will be your index.php, but the content will change based on the links the user goes to. Conclusion

Related:  mkwebonline toolsPHPPHP ProgrammingseyfseyfCoding 2usefull maybephp programming languagePHPPHPfelixklotzsche