Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Pawel Mikolajczuk:
Create custom Twig node and parser
Aug 28, 2017 @ 14:16:47

On his Mdeium.com site Pawel Mikolajczuk has written up a post showing you how to create a custom Twig node and parser to extend the powerful functionality already included in this popular PHP templating package.

If You want to create custom twig node then this tutorial is for You. I will show you step by step how to create custom twig syntax (DSL) called gimme (we build it for our Superdesk Publisher project).

He starts with the required changes to your composer.json file to pull Twig in and a sample index.php file to build the Twig instance and add in the new extension (the "gimmie" handling). He then provides the code needed to create the extension based on Twig_Extension for the new node type. Next is an example of the "gimmie" handling in action in a template, dumping out the user information when the article is requested. He explains what each part of the tag is doing and shares the code to create the parser for its contents. Finally he shares the code required to create the "node" class, converting it over to its parsed PHP equivalent.

tagged: tutorial twig template custom node tag gimmie extension

Link: https://medium.com/@pawel.mikolajczuk/create-custom-twig-node-and-parser-b9cc056102ee

Community News:
PHP 7.0.0 Beta 2 Tagged
Jul 23, 2015 @ 13:45:27

According to this post on Reddit.com (and this NEWS file update) the latest beta of PHP 7.0.0, beta 2, has officially been tagged.

Fixes include updates in several different areas of the codebase:

  • Curl
  • GD (graphics handling)
  • Opcache
  • SOAP
  • the SPL (Standard PHP Library, with MutlitpleIterator)

You can find out more about all of the bugs that were fixed (including a sneak peek at what's coming in beta 3) in the NEWS file.

tagged: language php7 tag beta release version

Link: https://github.com/php/php-src/blob/master/NEWS

Sameer Borate:
Adding WordPress like shortcodes to your web applications
Apr 24, 2015 @ 14:14:50

Sameer Borate has posted a new tutorial showing you how to add shortcode-like handling to your application. Shortcodes are a feature that's common in tools like WordPress to make adding custom markup easier (like "[tag][/tag]").

One of the cool features of WordPress is its shortcode feature. There may be times one wished to add this capability to your PHP web applications. Recently I found one such library which allows you to add shortcode features to your web apps. The library discussed here implements WordPress style shortcode syntax as a standalone package. Its a small package and so can be easily integrated into you existing applications. Content from editors, databases, etc. can be scanned by the Shortcode Manager and the contents replaced by a custom callback.

He makes use of the maiorano84/shortcodes library (installable through Composer) that makes it simple to add the functionality to your existing application. He includes a few examples of tag formats that the library can parse and the code needed to parse and handle the formatting. The custom tags are processed via callbacks and can modify the incoming value easily. He also shows how to access any attributes that may be set on the codes and grouping all of his functionality into one self-contained class.

tagged: shortcode wordpress tag custom library maiorano84 tutorial

Link: http://www.codediesel.com/php/adding-wordpress-like-shortcodes-to-your-web-applications/

SitePoint PHP Blog:
CMS Content Organization Structures: Trees vs Facets vs Tags
Feb 05, 2015 @ 17:38:35

In the latest post to the SitePoint PHP blog Lukas Smith takes a look at content management systems comparing trees versus facets versus tags in content organization.

For several years I have been interested in content repositories as a key aspect of modern CMS. With “modern”, I mean CMS that are not just “page management systems” but CMS that actually manage content, thereby enabling authors to reuse their content on different devices and even different applications. But when evaluating [prismic.io and contentful.com], I noticed a surprising trend: they do not leverage trees, neither as a native storage concept nor as a visualization concept. Instead, they for the most part rely on flat structures with tagging. My gut feeling was telling me that this was a mistake, especially when managing larger content repositories. At the same time I wondered: “Am I just a dinosaur that is missing the ark?”.

He starts with an introduction to the concepts of trees, facets and tags and starts in on the advantages and disadvantages of each. For each topic he shares a brief summary of what they are and a screenshot showing how they could be visualized. He finishes the post with a "tl;dr;" summarizing the points made for those wanting the basics.

tagged: cms content organization structure tree facet tag introduction

Link: http://www.sitepoint.com/cms-content-organization-structures-trees-vs-facets-vs-tags/

NetTuts.com:
Creating a Photo Tag Wall With Twilio Picture Messaging & PHP
Jan 10, 2014 @ 16:36:00

On NetTuts.com today there's a new tutorial that helps you create a "photo tag wall" using the Twilio picture messaging functionality and some PHP. The picture messaging service lets you send and receive photos over phone numbers and short codes.

Twilio’s recently announced Picture Messaging has vastly opened up what we can do with text messaging, now we can attach photos to our text messages and have them get used in different ways. In our case, we are going to build a Photo Tag Wall, which will contain photos linked to tags that will be displayed on a website. This can be handy for events, or parties, or just about anything where you want to associate photos and tags.

They use a combination of the Jolt microframework for the structure of the app, Idiorm/Paris for the MySQL handling and the Twilio PHP library to talk to their web service. They start by setting up the database tables for both the "tag" and "photo" (SQL included). They include a sample configuration file, used by the Twilio library, and get into the actual code. The first part shows how to make the request to the API and resize the fetched data into a correctly sized photo on the server. Then they get into the routing, making both a root path and a "listener" for the Twilio API to call when a new photo it sent. Finally, they set up the actual photo wall page, pulling the image data from the database and the image from the local file system.

tagged: photo tag wall tutorial twilio picture messaging mysql

Link: http://net.tutsplus.com/tutorials/php/creating-a-photo-tag-wall-with-twilio-picture-messaging-php

PHPMaster.com:
Create a Podcast Feed with PHP
Aug 14, 2013 @ 16:54:48

On PHPMaster.com there's a tutorial posted that walks you through the creation of a podcast feed based around a Slim framework application and this skeleton application.

In this article, I’ll demonstrate how to use PHP to generate a podcast feed. We’ll create a simple administrative interface to configure the podcast metadata, add and list episodes, and then go through the generation of the podcast feed itself (which is simply an RSS document).

He walks you through the full process - setting up the application, creating the various management pages and making the associated views to add more information to the feed. He also includes the code/markup you'll need for adding episodes and generating the actual XML RSS feed output. You can download the full app if you want to see how it's all laid out.

tagged: podcast tutorial feed id3 tag slim framework rss

Link: http://phpmaster.com/create-a-podcast-feed-with-php

Extending Twig Templates:
Inheritance, Filters, and Functions
Apr 16, 2013 @ 16:05:22

On PHPMaster.com today there's a new tutorial for the Twig templating users out there showing you how to extend your templates via inheritance, filters and functions - all abilities already built in to the tool.

When working within an MVC architecture, it’s common to use a template library to populate the dynamic content of our views. There are dozens of such libraries available for PHP, but Twig is one of the standouts because of the ability to extend core features with custom implementations. In this article we’ll explore how Twig templates can be extended using template inheritance, filters, and functions.

He starts first with some of the common limitations of templating frameworks (extension) and how Twig gets around this. He shows the use of the "extends" keyword and the "block"/"endblock" for splitting up the page into reusable chunks. He also shows how to use filters and functions in your Twig tags, allowing for more customized content and functionality for your output.

tagged: taig template tag filter function inheritance tutorial

Link: http://phpmaster.com/extending-twig-templates-inheritance-filters-and-functions/

SitePoint PHP Blog:
Should You Close Your PHP Code Tags?
Sep 20, 2010 @ 18:34:22

On the SitePoint PHP blog there's a new post with an interesting question for PHP developers that might go against how they were tought to code from their early days - should you close your PHP tags at the end of your code?

Even those with a modest grasp of PHP know that code must be enclosed within special tags. [...] However, if your file contains just PHP - and no escaped HTML code - the closing ?> tag is entirely optional. Many developers argue that unnecessary code should be removed but there's another reason you could consider scrapping the closing tag.

Their rationale is that, in some situations, extra characters or other information could pop up after that closing PHP tag and cause problems in your code. If you drop the closing tag completely, there's no risk that this could happen and PHP parses it the same way.

There's lots of great comments with opinions both for and against.

tagged: opinion close tag end error

Link:

Marco Tabini's Blog:
The origin of the <blink> tag
Jun 08, 2010 @ 16:33:21

In a recent post to his blog Marco Tabini talks about the "monkey on the back" syndrome that affects so much of the technology projects these days. His example for PHP? register_globals.

One such example is the register_globals setting in PHP which finally managed to get deprecated in PHP 5.3 (and, the way things are going, may never disappear altogether) after much fighting and gnawing of teeth. [...] The existence of register_globals is problematic in many ways, but it is consistent: as long as you have a version of PHP that supports it installed, you will have the opportunity to use it1. When it is discarded, it ceases to exist, so that rewriting your code becomes a prerequisite to upgrading to a new version of PHP.

He also relates it to a <blink> tag - something that really shouldn't be used any more but, because someone decided it was a good idea in the past, several browsers have included support for it. The moral of the story? Well-planned standards are a good thing.

tagged: blink tag registerglobals feature standards

Link:

Brian Moon's Blog:
The history of PHP eating newlines after the closing tag
Mar 04, 2009 @ 17:13:47

Brian Moon points out a (sometimes annoying) habit of PHP when it comes to newlines - it drops them after the closing tag.

Have you ever noticed that PHP eats the newlines after a closing PHP tag? Not sure what I mean? There is lots on Google about it. [...] So, why does PHP do this? Well, you have to go back 11 years. PHP 3 was emerging. I was just starting to use it for Phorum at the time. There were two reasons.

The first reason was the it, at least in the minds of the developers of the language, "removed all traces of PHP" from the script without any training newlines to show for it. The second case was a bit more valid - because lots of editors at the time required newlines at the end of every line of code. This caused loads of trouble tracking down things like the infamous "Headers already sent" issues (pre-output buffering).

tagged: closing tag newline remove reason headers editor

Link:


Trending Topics: