 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
PHPMaster.com: String Handling Functions
by Chris Cornutt December 26, 2011 @ 15:38:56
On PHPMaster.com today James Appleyard has put tother a tutorial for the beginners out there about working with strings in PHP, using the huge list of built-in functions to work with your values.
PHP has a vast selection of built-in string handling functions that allow you to easily manipulate strings in almost any possible way. [...] There is no way I can cover every string function in one article, and besides, that is what the PHP manual is for! But what I will do is show how to work with some of the most commonly used string handling functions that you should know. After this, you'll be working with strings as well as any concert violinist!
He shows how to use functions to: change the case of string, remove extra whitespace, get the length, slicing them up and doing replacing on some certain characters. You can find more information on these and the complete list of string functions in PHP in the manual.
voice your opinion now!
string handling function tutorial beginner
Lorna Mitchell's Blog: Handling SQL Errors in PDO
by Chris Cornutt November 16, 2011 @ 09:43:34
Lorna Mitchell has a quick new post showing one way to handle SQL errors in PDO that could pop up because of badly written/generated SQL statements.
I love PHP's PDO (PHP Data Objects) extension; it gives a consistent, object-oriented interface to handling all kinds of relational database backends. One thing that annoys me is that the MySQL driver for PDO defaults to a silent error mode which can make SQL errors tricky to spot!
In her two code snippets she shows a failing PDO request (that fails silently) and a method for catching this issue - checking the result of the "errorCode" method to see if it equals "0" (zero). If there were errors, you can use the "errorInfo" function to get to them. This will return the SQL error code, the driver-specific error code and a driver-specific error message.
voice your opinion now!
pdo error handling errorcode errorinfo tutorial
PHPMaster.com: Error Handling in PHP
by Chris Cornutt November 10, 2011 @ 08:41:39
On PHPMaster.com today there's a new tutorial from Sneha Heda looking at error handling in PHP - the types of errors that can come up, how to throw your own and how to catch them appropriately.
Errors are the most common event a developer faces when programming. [...] To help reduce the number of errors in your code, and to mitigate their effects, proper error handling is essential in your web application. This article is a crash course in PHP error handling. You'll learn about PHP's built-in error reporting levels, and how to handle errors with custom error handlers and exception handling.
She starts with the different error reporting levels PHP offers, everything from the lightweight E_NOTICE out to E_ALL|E_STRICT. With this as a reference, she shows how to create a custom error handler (using set_error_handler). Also included is a look at exceptions and some of the more detailed information that comes with them - line numbers, messages, file the error was thrown from, etc.
voice your opinion now!
error handling tutorial exception custom handler reporting level
NetTuts.com: The Ins and Outs of PHP Exceptions
by Chris Cornutt October 14, 2011 @ 08:44:32
On NetTuts.com today there's a new tutorial showing you the "ins and outs" of using exceptions in PHP - throwing them, handling the result and integrating them into your error handling process.
Still returning false whenever a function in your program fails? In this article, we'll learn about PHP exceptions, and how you can use them to soup up your application's error handling.
The include some of the methods you can call on your exceptions (including getting the message, code, file, line and the results of a debug_backtrace right before it was thrown). Included is code to throw exceptions, catch them with a try/catch and using error codes as return values and extending them to fit your own needs.
voice your opinion now!
exception handling throw tutorial extend example
PHPMaster.com: Array Handling Functions
by Chris Cornutt October 11, 2011 @ 08:37:55
On PHPMaster.com today there's a new tutorial introducing you to the array handling features in PHP - sorting, slicing and more.
In my previous article on PHP arrays I suggested a number of things that are tables and therefore can also be expressed as arrays. In this article I'll use a pack of playing cards to explore some of the built-in array functions most often needed by PHP programmers.
To highlight some of the array-handling functions PHP offers, I'll be using some components of Buraco - a game very popular in my part of the world and quite similar to Rummy.
In the example he represents a deck of cards with an array of values like "A", "03" and "13". This array is then looped to make the full set of 52 cards and shuffled to deal a "hand". Array functions put to use include array_rand, in_array and sort.
voice your opinion now!
array handling function tutorial example buraco card game
Nicolas Grekas (on Github): Improved handling of HTTP requests in PHP
by Chris Cornutt June 17, 2011 @ 09:39:41
As Nicolas Grekas shows in this tutorial (posted as a gist), the functionality that PHP gives users to work with the raw HTTP requests is pretty limited. There's a few solutions he offers, but none of them allow for the full use of the HTTP options provided by the server.
HP offers comprehensive autoglobals to access external data sent with each request. These variables do not expose all the possibilities allowed by the HTTP protocol, but a controlled use can in practice minimize the impact of this limitation. Two problems are particularly troublesome: the lack of access to multi-valued keys without using a special syntax and complexity of the magic bracketed syntax. Until PHP natively provides another interface freed from these problems, a different interface in user space can circumvent them.
He gives some code examples of methods that can be used to parse strings like those found in cookies (or pulled in via php://stdin) including mentions of key normalization and accessing the values by literal keys. You can see a more full implementation here.
voice your opinion now!
http handling improved requests tutorial parse
Jani Hartikainen's Blog: How to use built-in SPL exception classes for better error handling
by Chris Cornutt May 09, 2011 @ 08:47:12
On his blog today Jani Hartikainen looks at how you can use the SPL exception types to allow for better overall error handling in your application. Things like BadMethodCallException and OutOfBoundsException make the errors much more descriptive.
Since PHP 5, there has been a bundle of built-in exceptions - the "SPL exceptions" - in PHP. However, the documentation for these classes is quite lacking in examples, and it can be difficult to understand when you should be using them. The short answer is always.
The list of exception types he recommends include:
- BadMethodCallException
- DomainException
- LengthException
- OutOfRangeException
- UnexpectedValueException
For each he gives an example usage of it, sometimes including a bit of code to illustrate.
voice your opinion now!
spl standardphplibrary exception handling classes types
|
Community Events
Don't see your event here? Let us know!
|