PHP

Tips for OOP Programming with PHP- Part 2: Object Storage

Before starting this article/tutorial you should already be familiar with PHP, and basic class and object syntax. This article is going to go through some useful operations you can do with objects. The first thing I want to demonstrate is how to store objects and their member variables. class MyCart{ var $items; function add_item ($artnr, $num){ $this->items[$artnr] += $num; } } session_start(); $_SESSION[‘user_cart’] = new MyCart(); In this case we are storing the object in the session variable. It is a fairly painless process, and getting that stored object on the next page the user loads is just as easy, after session_start() it will be available just like a session variable. If you try to use the session stored object on a page that does not have the class’s declaration, class MyCart{}, you will get a generic object with no member functions, as explained on the PHP manual page ‘Object Serialization’. $user_cart = new MyCart(); $user_cart_string_data = serialize($user_cart); $fp = fopen(‘data.txt’, ‘w’); fwrite($fp, $user_cart_string_data); fclose($fp); This is another basic method of storing objects. We converted the object to a string representation, and made or overwrote a file with that data. If it is not already clear, you restore the object by reading the file into a string, then using unserialize on it, reversing the effects of serialize. Like the session type of storage, you need the class to be defined in any file that uses that type of object. […]

By | October 8th, 2011|PHP, PHP, PHP Articles, PHP Tutorials|Comments Off on Tips for OOP Programming with PHP- Part 2: Object Storage

PHP Regular Expression Techniques – Part 1: Pattern Modifiers

This article will focus on PHP’s regular expression functions with pattern modifiers. Specifically these functions are of the preg type, and have preg as the prefix. preg_match() is probably the most basic regular expression function of that type and some examples of it will be used in this article. Regular expressions provide versatile ways of searching text or ‘matching’ it. A string called a pattern is used, similar to a search phrase, and in this case the patterns take a form that is basically the same a the expressions in the Perl language. […]

By | October 4th, 2011|PHP, PHP, PHP Articles, PHP Tutorials|Comments Off on PHP Regular Expression Techniques – Part 1: Pattern Modifiers

Tips for OOP Programming with PHP- Part 1: Objects and References

Programming in PHP utilizing objects is not complex and the syntax and other basics are well covered in various articles and tutorials. It’s also covered in the PHP manual and I will include a brief example for those who need a refresher. Before that I am going to illustrate the basic principals of references without using objects at all. I will then build upon that example to show how use objects and references in your program in useful and efficient ways. […]

By | October 3rd, 2011|PHP, PHP, PHP Articles, PHP Tutorials|Comments Off on Tips for OOP Programming with PHP- Part 1: Objects and References

strlen and count in PHP5

strlen and count in PHP5 – The Basics If you are new to strlen and/or count in PHP, then you have come to the right place. In this article I will cover the basics you need to understand their uses, and move toward effectively implementing them in your own PHP projects. Both functions are used to count things, however what they count, and how they count them, are completely different. Understanding how they each work by themselves will allow you to use them together to accomplish some very useful things. However, for now, let’s start at the very beginning. […]

By | May 17th, 2011|PHP, PHP, PHP Articles|Comments Off on strlen and count in PHP5

PHP and cURL

Using curl with PHP is incredibly easy. Firstly you’ll need to make sure that you have the PHP curl library installed on your system. On Debian, this is as easy as apt-get install php5-curl Now you can try the following: […]

By | May 17th, 2011|PHP, PHP, PHP Articles|0 Comments

Rebuilding the Robot

It had been a while since I’d worked on the robot, and I wanted to work on some movement algorithms. I’ve done some AI work lately on a separate project, and thought that this would help with the automated movement task. Unfortunately, the Robot had a little accident, namely falling out of the loft whilst I was bring it down. It’s been long overdue the removal of some of the excess hardware, and also needed some bugfixes that I now had no choice but to perform. […]

By | May 1st, 2011|C/C++, Development, Hardware, PHP, Robot, Technology|0 Comments

Another PHP tip

While it’s all well and good to spend considerable time securing your PHP applications, there is something else that you can do, or rather not do. As a PHP programmer, I see people do one alarming thing: they download and install PHP applications from questionable sources. While there are a lot of honourable programmers who offer their scripts for free, there are plenty of hackers who enjoy deploying applications that cause harm to others. I discussed this earlier, but it bears repeating: trust your source. Know your source. […]

By | July 15th, 2010|Development, PHP, PHP, PHP Articles|0 Comments