 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Sameer's Blog: Easy way to build GET query strings in php
by Chris Cornutt November 13, 2008 @ 12:47:01
Sameer has come up with an easy way to build out query strings to use in your GET requests:
Passing variables with a url is such a frequent thing programmers do that most of you may think this post is unwarranted. We call this method of passing variables as GET, the other being POST. It is one of those things which can be easily done in php. [...] The best way to pass GET variables is to use the http_build_query() function available from php version 5; which takes an array of variables and builds a nice URL encoded string which you can append to a url. And example is shown below.
He includes two code examples - one showing "the old way" of building it out by hand and the other using the http_build_query function. You pass in an array and what to connect them with and it builds out the string, no matter how many arguments there are.
voice your opinion now!
php5 httpbuildquery query string build tutorial
CodeUtopia Blog: Generic collections in PHP
by Chris Cornutt September 19, 2008 @ 12:06:53
On the CodeUtopia blog Jani Hartikainen has posted some thoughts on generic collections in PHP and a class he's created to try to introduce them to the language.
Strictly typed languages usually use "generic" collection classes instead of arrays. They are kind of like PHP arrays which the programmer can tell which type of items to accept. This is of course only natural when you don't have dynamic typing, but it can also be useful for avoiding programming errors, so I thought I'd try making a basic generic collection class in PHP...
He shows how ti works with a simple code example - creating a new collection type (a string) and pushing the data into it. Calling the add() method on the string throws an exception because of the data type defined. You can grab the code from his svn repository.
voice your opinion now!
generic collection class download svn example string
PHP in Action: Type hints are more useful for scalars than objects
by Chris Cornutt September 11, 2008 @ 10:08:33
On the PHP in Action blog, there's a new post looking at a recent library that was posted to support type hinting on scalars. They agree with his choice of subjects, noting that they see type hinting as much more useful on scalars than on objects.
I admit that these judgments are hard to make. I could be wrong, more or less. Type hints are probably useful when code becomes stable enough and at the boundaries between modules. But I still tend to avoid using them until I get an actual bug that might have been prevented by a type hint. Their usefulness is and has to be an empirical question. The purpose of using them has to be catching errors earlier, so if they don't have that effect, there's no point.
He lists three reasons why he had given up on type hinting before, one being the limited usefulness when it came to objects. Applying it to scalars is a different matter, though, and can prevent improper passing of array/scalars when the other is needed.
voice your opinion now!
type hinting scalar object array string class library
Debuggable Blog: String substitution using UUIDs
by Chris Cornutt August 22, 2008 @ 12:04:39
On the Debuggable blog, Felix Geisendorfer shows how to create a string parser that allows you to pull out parts of the string you don't currently want manipulated to be put back later.
If you've ever written any non-trivial String processing code, you've probably ran into the situation where you wanted to exclude certain parts of your string for a certain operation. Usually that would mean you have to tokenize your string, or adjust the operation you want to run so it doesn't affect the part of the string you want to exclude from it. Both of those solutions can be fairly time intensive so I was looking for a shortcut and found one.
He provides the code for this string substitution class, a method substitute() that matches based on a regular expression and, if found, stores the parts for later use.
voice your opinion now!
string substitution uuid manipulation regularexpression
Ibuildings Blog: Implementing Iterators
by Chris Cornutt August 20, 2008 @ 15:02:59
On the Ibuildings blog Ruud Alberts takes a look at iterators - what they are and how they're used (including the objects the SPL makes available).
Let's kickstart this blogpost by defining what an iterator actually is. According to wikipedia, an iterator is. A collection can pretty much be anything. The most obvious sources would be arrays, but other than that, iterations can be done over database resultsets, strings, datetime intervals, directories, file content and XML listings, to name a few.
He looks at the iterator interface that comes bundled in the SPL and how you can create a custom one to loop through your own data collection. He includes an example - a colorful string iterator that "pretties up" an HTML string with various colors.
voice your opinion now!
iterator standard library spl custom color string tutorial
Jonathan Street's Blog: Random thoughts on random strings
by Chris Cornutt July 03, 2008 @ 07:58:33
On his blog, Jonathan Street has posted some "random thoughts" on generating random (or not so random) strings in PHP.
Humans are astoundingly bad at being random and I just slapped the keyboard a few times until I felt I had the required 16 characters. Writing some code to produce a fairly random string is incredibly easy. I've easily done it a dozen times or more. Though only because it is easier to re-write it than to find where I put the last one
He gives two examples that work, but aren't the best possibilities for making truly random strings - one using mt_rand to select a random character from a string and the other using the same idea but instead using the char() function to replace the string of characters.
His other examples include the use of the uniqid function with the more_entropy setting enabled and an md5 or sha1 hash (for which he gives positives and negtives).
voice your opinion now!
random string mtrand md5 sha1 chr uniqid moreentropy
ProDevTips Blog: Fluent Arrays and Strings in PHP
by Chris Cornutt June 23, 2008 @ 07:57:18
On the ProDevTips blog, Henrik has written up an extensive tutorial with plenty of code examples on working with something inspired by a few other languages - fluent arrays and strings.
I've been working some with jQuery and Ruby lately, as you might know they both have very neat fluent interfaces for writing short and easily understandable code. Especially Ruby's array and string handling should be something that can be done in PHP so I started googling. [...] It's probably very possible that what I'm looking for is already part of some PHP framework or such but I didn't want to spend more time looking than being productive.
Based on some Ruby examples, he defines a set of functions that can be use to create these fluent interfaces to the common PHP variable types (contained in a class for easy use). The entire source can be downloded here.
voice your opinion now!
fluent string array class source download tutorial
|
Community Events
Don't see your event here? Let us know!
|