Knowledge7

The Linux and Mobile Solution Provider

  • About
  • Training
  • Services
  • Clients
  • In the news
  • Blog
  • Contact Us
You are here: Home / Blog

Parsing JSON and XML documents

This topic is part of our Web Development with PHP and MySQL training

Flickr has a public API which can return a JSON response containing a list of photos on Flickr tagged with a specific keyword.

The work to do is to add to the web application a feature where one can see recent photos on Flickr tagged with the name of the mobile phone being examined. For example, when someone is looking at the Nokia E75, he/she should be able to see Flickr photos tagged with nokiae75.

RSS (which is XML) is also very common on the web. For instance, all blogs have a RSS feed including Nokia’s where the latest news on Nokia mobile phones can be easily read.

The work to do is to add these latest news on the homepage on the web application. For that, the RSS feed needs to be read from the Nokia’s blog, parsed as an XML file and the appropriate HMTL generated.

This topic is part of our Web Development with PHP and MySQL training

Our forthcoming training courses

  • No training courses are scheduled.

Using filters and templates in PHP

This topic is part of our Web Development with PHP and MySQL training

An order form can be added to the website created before in order to transform it into an e-commerce website. When someone orders a phone, the order should be saved to a text file. A reporting facility can also be added.

Filters were recently added to PHP in order to provide sanitization as well as validation facilities. The work to do is to make sure that any data being submitted from the order form is properly sanitized and validated. This helps in making the web application more secure.

Usual PHP scripts mix both programming elements (the PHP) with HTML markup. This tends to make the web application less maintainable and can prevent web designers and programmers from working at the same time.

One common solution to that problem is to use a templating engine like Smarty. This engine allows the programmer to separate PHP from HTML markup while increasing flexibility. The work to do is to rewrite the web application to use Smarty.

This topic is part of our Web Development with PHP and MySQL training

Our forthcoming training courses

  • No training courses are scheduled.

Object-Oriented Programming

This topic is part of our Object-Oriented Programming in PHP training

When version 5.0 was released in 2004, PHP became a full-fledged Object-Oriented Programming Language (similar to Java and C#).

Exercises

We will implement a web application which manages people, dogs and cars in a number of steps until we have explored the most important object-oriented constructs found in PHP5:

  1. Implement the Person and Dog classes (+ required constructors, methods, attributes) and instantiate one object from each class.
  2. Add visibility constructs (private for attributes / public for methods).
  3. Add the Car class with its association as shown in the above diagram. Given that PHP is dynamically typed, what is the risk here?
  4. Use type hints to prevent type mismatch.
  5. Implement the Nameable interface as well as the Nameables class (use an array to hold references). Implement getNames() using foreach(). Use type hints to prevent type mismatch.
  6. Use an exceptions for error handling when someone attempts to create a Car with no number.
  7. Replace the exception by a custom exception.
  8. Use inheritance (sparingly) to create a specialized version of Person called Doctor with a special behaviour for getName().
  9. Replace the array in Nameables by a SplDoublyLinkedList of the Standard PHP library.
  10. Use mktime to make sure that each Car created has a registration date of 25 December 2010 at 10:00
  11. Use strtotime to make sure that each Car created has a first servicing date which is next Saturday at 10:00.
  12. Use strtotime to make sure that each Car created has a second servicing date which is exactly three months after the first one.
  13. Use a static attribute which are shared among all Cars to keep a count of all Cars which have been instantiated.
This topic is part of our Object-Oriented Programming in PHP training

Our forthcoming training courses

  • No training courses are scheduled.

Les réseaux sociaux et l’entreprise

[J’ai écrit cet article pour le Numéro 3 du magazine 100% Mauricien, TechKnow.]

Depuis son lancement en février 2004, le réseau social Facebook a pris beaucoup d’ampleur et est maintenant utilisé par près d’un demi milliard de personnes (ce qui équivaut à une personne sur treize sur la planète.) Logiquement, Facebook est aussi très populaire parmi nos concitoyens et nous recensons presque 225,000 d’entre eux sur ce réseau social (ce qui équivaut à un Mauricien sur cinq.) Naturellement, nous pouvons affirmer sans trop se risquer que beaucoup de ces 225,000 Mauriciens sont plutôt instruits et plutôt confortables financièrement.

[img_assist|nid=180|title=|desc=|link=none|align=center|width=450|height=393]

Le Central Statistics Office publie des données précises sur la composition de la population mauricienne et, lorsque nous corrélons ces chiffres avec ce que Facebook publie, nous constatons que presque un adolescent de Maurice sur trois y est présent ainsi qu’un adulte sur quatre. Du point de vue démographique, nous voyons aussi que Facebook est légèrement plus populaire parmi les garçons que les filles et que les 13-18 (adolescents), 18-22 (étudiants au niveau tertiaire), 22-30 (jeunes professionnels) et les 30-45 (cadres de niveau intermédiaire) y sont bien représentés. Certaines études montrent que les 45-60 (cadres supérieurs) et les 60+ (retraités) sont les tranches d’age en plus forte progression sur Facebook dans le monde. En d’autres mots, à terme, presque tout le monde sera sur ce réseau social.

Des annonces plus ciblées

Henry Ford, père de la voiture moderne, avait observé: « Half of every dollar I spent on advertising was wasted. I just didn’t know which half. » En effet, personne n’est jamais sûr qu’une publicité sera vraiment vue par sa cible.

[img_assist|nid=181|title=|desc=|link=none|align=center|width=450|height=299]

Sur Facebook, il est possible de créer une annonce (qui peut bien sûr être une publicité) et qui ne sera affichée qu’à un public très précis. Par exemple, nous pouvons restreindre la visibilité qu’à ceux habitant un pays précis (e.g. Maurice), une tranche d’âge donnée (e.g. 18-25), un sexe donné (e.g. de sexe féminin), avec des centres d’intérêt spécifiques (e.g. ayant exprimé un goût pour les voitures), avec un statut marital donné (e.g. célibataire) et possédant un niveau d’étude précis (e.g. universitaire). Naturellement, si cette annonce est conçue correctement, la probabilité que l’audience cible clique dessus augmente exponentiellement.

Qu’arrive-t-il lorsque quelqu’un clique sur une annonce? Sur Facebook, il existe deux possibilités. Dans un premier cas, cliquer envoie la personne sur un site web externe à Facebook (e.g. le site web de l’entreprise qui propose les produits vantés dans l’annonce.) Il est même possible que la page affichée soit une page d’accueil différente de la page principale du site web et qui est conçue spécifiquement pour ce public très ciblé.

[img_assist|nid=182|title=|desc=|link=none|align=center|width=450|height=301]

La deuxième alternative est que le clic envoie la personne sur une page Facebook spécialement conçue pour provoquer une interaction forte entre l’entreprise et ce public intéressé. Par exemple, Starbucks Coffee a une présence sur Facebook et a, à ce jour, presque 15 millions de fans. L’intérêt pour Starbucks Coffee est de pouvoir très facilement alors faire passer des messages (e.g. nouveaux produits, nouvelles offres, etc.) à ces fans à peu de frais.

Le Buzz Marketing

On fait plus confiance à un ami qu’à un étranger. Donc qui mieux qu’un ami pour faire la promotion d’un produit? Sur les réseaux sociaux, dès que quelqu’un montre son intérêt pour quelque chose (e.g. en devenant un fan de Starbucks Coffee), tous ses amis sont immédiatement notifiés. Ce type de marketing, que nous pouvons qualifier de viral (parce qu’il se propage comme un virus) est aussi connu comme le « Buzz Marketing » En peu de temps, un produit (ou une marque) peu connu peut se faire connaître en un temps record en utilisant cet effet réseau. N’est-il pas vrai que Frigyes Karinthy a émis l’hypothèse que « everyone is at most six steps away from any other person on Earth, so that a chain of a friend of a friend statements can be made to connect any two people in six steps or fewer »?

Aujourd’hui, l’accent doit être mis sur du contenu multimédia (vidéos et images fixes) pour captiver l’attention des gens. De plus en plus, les entreprises utilisent des applications Facebook et/ou fonctionnant sur les smartphones (iPhone, Android, etc.) pour créer des liens encore plus forts avec ce nouveau public. Développer une application Facebook ou mobile demande une expertise technique que peu d’entreprises possèdent. Cette activité est donc souvent externalisée.

Cette année, un fabricant de voitures très connu, a créé une page sur Facebook (utilisée par presque six millions de personnes à ce jour) et a ensuite incité les gens à les rejoindre sur ce réseau social en utilisant des publicités à la télévision!

Comment augmenter les ventes?

Des études ont montré que les gens aiment beaucoup les coupons de réduction et que ceux-ci les incitent à se déplacer dans les magasins. Grâce aux réseaux sociaux, il devient facile et peu onéreux de distribuer ces coupons et beaucoup d’entreprises (mais pas nécessairement à Maurice) l’ont compris. Par exemple, Domino Pizza et les supermarchés Food Lion, tout deux des États Unis, ont une présence sur Facebook et possèdent de nombreux fans. Ils utilisent cette plateforme de communication pour inciter les gens à venir dans leurs magasins en leur offrant des cadeaux ainsi que des coupons de fidélité.

Naturellement, pour que cela fonctionne, il est important que la relation entre l’entreprise et ses fans soit cordiale. Pour cela, il est essentiel qu’une personne (salariée de l’entreprise ou non, mais dans tous les cas, pouvant parler au nom de l’entreprise) soit constamment à l’écoute des fans pour pouvoir leur répondre (surtout s’ils émettent un avis défavorable) à l’instar du Chief Listening Officer de Dell, Susan Beebe. Le pire étant bien sûr d’avoir une présence sur les réseaux sociaux avec beaucoup de « fans » mais où tous se plaignent…

Le monde a (déjà) changé

Le consommateur dans un futur très proche sera équipé d’un smartphone (voir mon article du mois dernier) offrant des possibilités de géolocation et sera constamment connecté avec ses amis à travers les réseaux sociaux. L’entreprise aura à adapter sa communication pour pouvoir correctement cibler ce consommateur. Aujourd’hui, nous n’en sommes qu’aux balbutiements (Facebook n’a que six ans après tout…) mais qui peut dire ce que 2015 nous réserve? En tout cas, nous serons tous sur Internet.

Our forthcoming training courses

  • No training courses are scheduled.

Design Patterns

This topic is part of our Object-Oriented Programming in PHP training

A Design Pattern is a solution which experienced software developers have been using over the years when they have to solve a given type of problem. The most popular book covering the fundamental Design Patterns is:

Useful design patterns include:

  • creational patterns like Abstract factory and Singleton,
  • structural patterns like Adapter (or Façade) and Composite and
  • behavioral patterns like Observer and Strategy

Exercises

We will implement an event database using our knowledge of object-oriented programming and design patterns.

The domain logic of the web application is:

Implement the following:

  1. User domainlogic class with its unit test
  2. Event domainlogic class with its unit test
  3. Repository domainlogic class with its unit test (together with helper classes if needed)

The persistence layer of the application is based on the Strategy design pattern. Implement:

  1. The Database and the Engine interface (its concrete classes will be implemented later…)
  2. InMemoryEngine which manages data in memory.
  3. Create a main menu as well as functionality to show all events
  4. Show events for a specific period
  5. Show events by keyword
  6. Show events falling on a specific date
  7. Create a new event (not really useful because we are using an in memory database…)
  8. Consequently, replace the in memory database engine by a MySQL database engine.
This topic is part of our Object-Oriented Programming in PHP training

Our forthcoming training courses

  • No training courses are scheduled.

Using a CSS Framework

This topic is part of our Web Development with PHP and MySQL training

A lot of web designers believe that it is a waste of time to write CSS from scratch. It is better to use an existing CSS framework and build upon that.

One good framework is Blueprint. It provides a flexible grid on which the presentation of a website can be based. Consequently, it is easy to experiment with different layouts. Of course, Blueprint is compatible with all major browsers.

The work to do is to replace the most of the “hand written” CSS in the previous example with Blueprint to increase maintainability.

This topic is part of our Web Development with PHP and MySQL training

Our forthcoming training courses

  • No training courses are scheduled.

Developing semantic W3C compliant web pages

This topic is part of our Web Development with PHP and MySQL training

People use HTML and CSS to create web pages. Over the years, a number of good design principles have been identified and, when followed, allow anyone to produce websites which are standards-compliant, compatible with all the major websites yet flexible and easily maintainable.

The principles are:

  • Build websites using semantic HTML. Previously, HTML pages mixed structure and presentation. Now, people use CSS for presentation which implies that HTML should only contain the structure of a document. Semantic HTML goes further, in the sense that it uses markup to reinforce the semantics (i.e. the meaning) of a document. For example, only one H1 should be used in a document as one document cannot possibly have more than one main title.
  • Use CSS for formatting. Typographic attributes (e.g. typefaces, weight, etc.) as well as colours, margins, backgrounds, etc. should always be specified in a CSS stylesheet which is linked from the HTML file.
  • Use CSS for positioning. For many years, people used HTML tables for positioning objects on an HTML page but this was brittle and tended to produce bloated webpages.

The work to do is to progressively create a website like the one pictured above using semantic HTML first, then writing CSS “manually” both for formatting and positioning.

Note that web standards are in constant evolution. For example, there is a lot of buzz around HTML5 and CSS3 right now even though the standardisation process is still in progress.

This topic is part of our Web Development with PHP and MySQL training

Our forthcoming training courses

  • No training courses are scheduled.

PHP and the Web

This topic is part of our Object-Oriented Programming in PHP training

Linux, Apache, MySQL and PHP are collectively known as the LAMP software bundle and power most of the websites of the planet.

Linux is the most popular operating system on the Internet today. It’s powerful, reliable and, most of the time, free. Linux powers all of Google’s as well as Amazon’s infrastructure for instance. Apache is the most popular web server used. According to Netcraft, Apache powers 60% of all websites in January 2011. MySQL is the most popular relational database used in the world.

And, finally, PHP is also very popular. WordPress, Drupal and Joomla are written in PHP and, of course, Wikipedia and Facebook are too.

In other words, PHP (together with Linux, Apache and MySQL) power a large part of the Internet.

Exercises

We wish to automate the buying of auto parts online. We will proceed in steps until we get a reasonable web application. Write simple PHP scripts to do the following:

  1. Display static text (typically, “HelloWorld”) when a form is submitted
  2. Display dynamic text (using the date() function) when a form is submitted
  3. Accessing form variables using superglobals $_GET, $_POST and/or $_REQUEST
  4. Display form variables using string interpolation
  5. Use HEREDOCS
  6. Use variables (integer, float, string, boolean, array, object), constants, operators (string, arithmetic, comparison, logical, error suppression @, execution `) to do calculations
  7. Use numberformat to format currencies appropriately
  8. Use if statements to test the existence of form variables and to make the script work gracefully if form variables do not exist or contain non valid data
  9. Use elseif to offer discounts depending on quantity of products ordered
  10. Use switch to display appropriate messages depending on how the customer has discovered the website
  11. Use loops (i.e. while and/or for) to display shipping rates which depend on distance travelled
  12. Store orders in a file and write a script to display all past orders
  13. Use arrays to summarise all past orders
  14. Use foreach and associative arrays to display help pages on various topics (shipping, warranty, contact)
  15. Use functions and array_walk to simplify the display of help pages
This topic is part of our Object-Oriented Programming in PHP training

Our forthcoming training courses

  • No training courses are scheduled.

The PHP Programming Language

This topic is part of our Object-Oriented Programming in PHP training

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

  • Official website for PHP
  • PHP on Wikipedia

PHP is an imperative programming language belonging to the C family and, as such, follows the C syntax, has control structures such as the if statement and loops (while, for, foreach etc). PHP also has variables, functions and supports object-oriented programming.

This topic is part of our Object-Oriented Programming in PHP training

Our forthcoming training courses

  • No training courses are scheduled.

Launching our new Internet Strategy service

Knowledge7 is proud to launch an Internet Marketing service today.

If we go back six years before, Facebook did not even exist and today we can’t even think how our lives would be without Facebook. Updating our status, checking friends profile, writing on their walls, updating pictures, liking and commenting on friends activities has become part of people’s daily routine. Its all about socialisation 2.0.

But Facebook is not just for keeping track of friends activities. It can also be used as a highly effective business tool. Many companies have already understood the potential of using such a dynamic platform to reach out to their customers and engage them. Most of them have started using their Facebook pages to provide their customers with updates, discount vouchers and other exclusive offers to their Facebook fans. Companies marketing efforts are more and more concentrated on Facebook to drive customers to the stores and consequently increase their sales and customer loyalty through word of mouth/viral marketing.

Domino’s Pizza UK with a fanbase of 39 000 has been able to increase sales and profitablilty through such activities on Facebook and Foursquare. They have noted an increase in profits by nearly 29% in only 26 weeks and what is more interesting is that 1/3 of sales was generated online. Starbucks is another success story of a company using the power of viral marketing on Facebook. To date they have more than 15 million of followers worldwide.

At Knowledge7, we make sure your business get noticed on social networks. We combine our deep understanding of social media and marketing to deliver creative and interactive online experiences. We monitor and make sure your company is part of the Internet community in order to maximise your ROI.

Call us on 5834-9001 now!

Our forthcoming training courses

  • No training courses are scheduled.
« Previous Page
Next Page »

Looking for something?

Want to know more?

Get our newsletter

Discover the latest news, tips and tricks on Linux, the Web and Mobile technologies every week for FREE

This work is licensed by Knowledge7 under an Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) license.