Spiga

Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Dynamic Web Template with Smarty Template Engine

Smarty Template Engine or more accurately described as "Template / Presentation Framework" is a tool that can ease the programmer to create website templates. Although it can be used for purposes as simple as that, its focus is fast and pain on the development and Deployment of your applications, while maintaining high performance, scalability, security and future growth.

Smarty features:

  • Caching: Smarty provides fine-grained caching features for caching all or parts of a rendered web page, or leaving parts uncached. Programmers can register template functions as cacheable or non-cachable, group cached pages into logical units for easier management, etc.
  • Configuration Files: Smarty can assign variables pulled from configuration files. Template designers can maintain values common to several templates in one location without intervention from the programmer, and config variables can easily be shared between the programming and presentation portions of the application.

  • Security: Templates do not contain PHP code. Therefore, a template designer is not unleashed with the full power of PHP, but only the subset of functionality made available to them from the programmer (application code.)

  • Easy to Use and Maintain: Web page designers are not dealing with PHP code syntax, but instead an easy-to-use templating syntax not much different than plain HTML. The templates are a very close representation of the final output, dramatically shortening the design cycle.

  • Variable Modifiers: The content of assigned variables can easily be adjusted at display-time with modifiers, such as displaying in all upper-case, html-escaped, formatting dates, truncating text blocks, adding spaces between characters, etc. Again, this is accomplished with no intervention from the programmer.

  • Template Functions: Many functions are available to the template designer to handle tasks such as generating HTML code segments (dropdowns, tables, pop-ups, etc.), displaying content from other templates in-line, looping over arrays of content, formatting text for e-mail output, cycling though colors, etc.

  • Filters: The programmer has complete control of template output and compiled template content with pre-filters, post-filters and output-filters.

  • Resources: Templates can be pulled from any number of sources by creating new resource handlers, then using them in the templates.

  • Plugins: Almost every aspect of Smarty is controlled through the use of plugins. They are generally as easy as dropping them into the plugin directory and then mentioning them in the template or using them in the application code. Many user-community contributions are also available. (See the plugins section of the forum and wiki.)

  • Add-ons: Many user-community contributed Add-ons are available such as Pagination, Form Validation, Drop Down Menus, Calendar Date Pickers, etc. These tools help speed up the development cycle, there is no need to re-invent the wheel or debug code that is already stable and ready for deployment. (see the Add-ons section of the forum and wiki.)

  • Debugging: Smarty comes with a built-in debugging console so the template designer can see all of the assigned variables and the programmer can investigate template rendering speeds.

  • Compiling: Smarty compiles templates into PHP code behind the scenes, eliminating run-time parsing of templates.

  • Performance: Smarty performs extremely well, despite its vast feature set. Most of Smarty's capabilities lie in plugins that are loaded on-demand. Smarty comes with numerous presentation tools, minimizing your application code and resulting in quicker, less error-prone application development/deployment. Smarty templates get compiled to PHP files internally (once), eliminating costly template file scans and leveraging the speed of PHP op-code accelerators.

Read more info about Smarty here: http://www.smarty.net/
Download Smarty here: http://www.smarty.net/download.php

PHP Tutorial : String Operations

Operating string so important in programming especially in PHP. Why so important? Because the work with php, is building a good information system, facilities to make searching the web, and various other things related to web development is not separated from the operating string. So many functions that have a string operation, and also a lot of string functions that are frequently used, so that authors need to share a few articles about this string operation. For the first part of the article the author will explain the function of which has 2 additional tasks other than the search string. Among other :

  • substr()
  • strstr()
Substr(), has a function to retrieve one or more characters from a variable. Implementation, such as taking the characters generated from the function DATE() is mysql. Sample usage is as follows :
<?php

$tanggal = '012409';
$bulan = substr($date, 0, 2);

$hari = substr($date, 2, 2);
$tahun = substr($date, -2);

echo "$hari/$bulan/$tahun";

?>
The result is:
24/01/09

Explanation is as follows:

$month = substr($date, 0, 2);
Take a 2-digit characters from the front, the result is 01.

$day = substr($date, 2, 2);
Take the characters from 2 to 3 digits. Because the string has a sequence beginning 0, then the number 2 in the variable $date have in order to position 2. The result is 24.

To prove it:
<?php
$date ='012409 ';
echo $date [2];
?>
the results are :
2

And the last is
$year = substr($date, -2); This means take 2 characters from the back. The result is 09.

Strstr(), this function is used to return all the strings behind the string searched. For example there is a sentence:
"Smartness radiated from the eternal pure handsome. - Al-k",
the characters are searching "--",
the results of the function strstr() is "- Al-k"

Example of use:

The result is:
- Al-k

Implementation of strstr() example like this:

Explanation is as follows:

if ($theword = strstr($sentence, $alert)) ( if the characters in the search in this case the $sign in the string $sentence, then return the string that are behind these variables into the $theword.

echo 'The phrase is in a cool earlier by'."'". substr($theword, strlen($sign ))."'";

part is essentially substr($theword, strlen($sign))

If the change in value is actually
substr( "- Al-k", 2);

show the search string with a pass mark of --.

The result is:
Al-k


So that the results of the integrity of the script

Is:
Expression earlier in a dogged by 'Al-k'


Strstr(), this function is used to return all the strings behind the string searched. For example there is a sentence: "Smartness radiated from the eternal pure handsome. - Al-k",
the characters are searching "--",
the results of the function strstr() is "- Al-k"

Example of use:
<?php

$sentence = "smartness radiated from the eternal pure handsome. - Al-k";
$sign ='--';
$theword = strstr($sentence, $sign);
echo $theword;

?>

The result is:
- Al-k


Implementation of strstr() example like this:

<?php

$sentence = "smartness radiated from the eternal pure handsome. - Al-k";
$sign ='--';

if($theword = strstr($sentence, $alert)) (
echo 'The phrase is in a cool earlier by'."'". substr($theword, strlen($sign))."'";
Else()
echo "dont have any expression!";
)

?>

Explanation is as follows:

if ($theword = strstr($sentence, $alert)) (

if the characters in the search in this case the $sign in the string $sentence, then return the string that are behind these variables into the $theword.

echo 'The phrase is in a cool earlier by'."'". substr($theword, strlen($sign ))."'";

part is essentially substr($theword, strlen($sign))

If the change in value is actually

substr( "- Al-k", 2)

show the search string with a pass mark of --.

The result is:
Al-k

So that the results of the integrity of the script
<? php

$sentence = "smartness radiated from the eternal pure handsome. - Al-k";
$sign ='--';

if ($theword = strstr($sentence, $alert)) (
echo 'The phrase is in a cool earlier by'."'". substr($theword, strlen($sign ))."'";
Else()
echo "Dont have any expression!";
)

?>

The result is:
Expression earlier in a dogged by 'Al-k'


OK.. thats it for now, see you at next tutorial!

This tutorial translated from: http://www.ilmuwebsite.com/

How C Programming Works

The C programming language is a popular and widely used programming language for creating computer programs. Programmers around the world embrace C because it gives maximum control and efficiency to the programmer. If you are a programmer, or if you are interested in becoming a programmer, there are a couple of benefits you gain from learning C:

  • You will be able to read and write code for a large number of platforms -- everything from microcontrollers to the most advanced scientific systems can be written in C, and many modern operating systems are written in C.

  • The jump to the object oriented C++ language becomes much easier. C++ is an extension of C, and it is nearly impossible to learn C++ without learning C first.


This animation shows the execution of a simple C program. By the end of this article you will understand how it works!

In this article, we will walk through the entire language and show you how to become a C programmer, starting at the beginning. You will be amazed at all of the different things you can create once you know C!

XML Tutorial Part 5 : XML Syntax

XML syntax refers to the rules that determine how an XML application can be written. The XML syntax is very straight forward, and this makes XML very easy to learn. Below are the main points to remember when creating XML documents.

Well-formedness

The W3C specifies that all XML documents must be well-formed. Specifically, a textual object is a well-formed XML document if:

  • Taken as a whole, it matches the production labeled document
  • It meets all the well-formedness constraints given the XML specification
  • Each of the parsed entities which is referenced directly or indirectly within the document is well-formed

If this all sounds confusing, don't worry too much. Basically, all you need to do is ensure you build your XML applications correctly!

XML Declaration

If you include an XML declaration, it must be the first item in your document. The XML declaration uses the element.

Example:


 

One Root Element Only

Each XML document must have one root element and no more. All other elements must be contained within the root element.

Example:


Data
More Data

XML Markup

Generally speaking, an XML document consists of markup and data. Markup is provided in the form of tags and attributes. Data is the text that goes in between the tags or is provided within their attributes.

The next couple of lessons cover the key syntax rules related to elements and attributes.

XML Tutorial Part 4 : XML Documents

XML Documents

This lesson shows you how XML documents are constructed. Similar to an HTML document, XML documents consist of stuff at the top of the document, followed by the content.


Prolog

Right at the top of the document, we have a prolog (also spelt prologue). A prolog is optional, but if it is included, it should become at the beginning of the document. The prolog can contain things such as the XML declaration, comments, processing instructions, white space, and document type declarations. Although the prolog (and everything in it) is optional, it's recommended that you include the XML declaration in your XML documents.

XML Declaration

The XML declaration indicates that the document is written in XML and specifies which version of XML. The XML declaration, if included, must be on the first line of the document.

The XML declaration can also specify the language encoding for the document (optional) and if the application refers to external entities (optional). In our example, we specify that the document uses UTF-8 encoding (although we don't really need to as UTF-8 is the default), and we specify that the document refers to external entities by using standalone="no". This is not a standalone document as it relies on an external resource (i.e. the DTD).

Although the XML declaration is optional, the W3C recommends that you include it in your XML documents. In any case, you'll need the XML declaration to successfully validate your document.

Document Type Definition (DTD)

The DTD defines the rules of your XML document. Although XML itself has rules, the rules defined in a DTD are specific to your own needs. More specifically, the DTD allows you to specify the names of the elements that are allowed in the document, which elements are allowed to be nested inside other elements, and which elements can only contain data.

The DTD is used when you validate your XML document. Any application that uses the document must stop processing if the document doesn't adhere to the DTD.

DTDs can be internal (i.e. specified within the document) or external (i.e. specified in an external file). In our example, the DTD is external.

Comments

XML comments begin with . Similar to HTML comments, XML comments allow you to write stuff within your document without it being parsed by the processor. You normally write comments as an explanatory note to yourself or another programmer. Comments can appear anywhere within your document.

Processing Instructions

Processing instructions begin with and end with ?>. Processing instructions are instructions for the XML processor. Processing instructions are not built into the XML recommendation. Rather, they are processor-dependant so not all processors understand all processing instructions. Our example is a common processing instruction that many processors understand. The instructions to the processor is to use an external style sheet.

White Space

White space is simply blank space created by carriage returns, line feeds, tabs, and/or spaces. White space doesn't affect the processing of the document, so you can choose to include whitespace or not.

Technically speaking, the XML recommendation specifies that XML documents use the UNIX convention for line endings. This means that you should use a linefeed character only (ASCII code 10) to indicate the end of a line.

Speaking of white space, there is a special attribute (xml:whitespace) that you can use to preserve whitespace within your elements (but we won't concern ourselves with that just now).

Elements & Content

This is where the document's content goes. It consists of one or more elements, nested within a single root element.

Root Element Opening Tag

All XML documents must have one (and only one) root element. All other elements must be nested inside this root element. In other words, the root element must contain all other elements within the document. Therefore, the first tag in the document will always be the opening tag of the root element (the closing tag will always be at the bottom of the document).

Child Elements and Content

These are the elements that are contained within the root element. Elements are usually represented by an opening and closing tag. Data and other elements reside between the opening and closing tag of an element.

Although most elements contain an opening and closing tag, XML allows you to use empty elements. An empty element is one without a closing tag. You might be familiar with some empty elements used in HTML such as the element or the
element. In XML, you must close empty elements with a forward slash before the > symbol. For example,
.

Elements can also contain one or more attributes. An attribute is a name/value pair, that you place within an opening tag, which allows you to provide extra information about an element. You may be familiar with attributes in HTML. For example, the HTML img tag requires the src attribute which specifies the location of an image (eg, ).

Root Element Closing Tag

The last tag of the document will always be the closing tag of the root element. This is because all other elements are nested inside the root element.

XML Tutorial Part 3 : XML Editor

XML Editor

As you saw in the previous lesson, you can create XML documents using a simple text editor such as Notepad, WordPad, vi, emacs, or SimpleText etc. Text editors are OK, but if you're serious about creating XML, you'd be better off finding an XML editor.

Benefits of an XML Editor

An XML editor will make your life easier when coding XML and more importantly, it will help prevent you from making errors.

XML editors are similar to HTML editors (or any other programming editor) in that they provide syntax highlighting which helps with readability when you're coding. They'll also do things like automatically insert a closing tag once you're added an opening tag.

A good XML editor should also provide validation - a way for you to validate that the documents you create are well formed.

Examples of XML Editors

Here are some XML editors you might find useful:

XML Tutorial Part 2 : XML Viewers

XML Viewers

While you can view XML documents with a simple text editor, there are free XML viewers that present the contents in a more readable form. XML viewers interpret the document so it will display the XML document using any styles that have been applied using XSLT or CSS. It will also warn you if something doesn't look right, or if it doesn't validate correctly.

Most modern browsers include XML support, so it's quite possible that your own browser is able to display the contents of XML files.

You open an XML file in your browser the same way you open any other file in your browser. If it's a local file you can type the full path into the address bar. Otherwise, if it's available over the web, you can type the URL into the address bar.

Notepad

You can use a text editor such as Notepad to create or view a simple XML file. Here's what this XML file looks like in Notepad:

Viewing an XML file in Notepad

Firefox

Here's how the above XML file appears in Firefox 2.0. Notice the difference between Notepad and Firefox. Firefox actually attempts to interpret the document. It even warns us if it thinks something could be out of place (such as a missing stylesheet).

Viewing an XML file in Firefox

Internet Explorer

Here's how the same XML file appears in Internet Explorer 6.0

Viewing an XML file in Internet Explorer

Displaying Errors

If your XML document contains an error, your XML viewer should display a message indicating the error. In this file, I have purposely included an error.

Below is how the error is reported in Internet Explorer.

Viewing an error in an XML file

Adding Styles

Once you start adding styles to your XML, you'll see a huge difference in how your XML documents appear with an XML viewer. We'll cover styles later.

XML Tutorial Part 1 : About XML

About XML

XML stands for eXtensible Markup Language. As the name suggests, XML is a markup language. The XML specification was created by the World Wide Web Consortium (W3C), the body that sets standards for the web.

Features/Benefits of XML

XML has been widely adopted since its creation and with good reason. Some of the key features and benefits of XML include:

  • Easy data exchange - One of the great things about XML is that it can allow easy sharing of data between different applications - even if these applications are written in different languages and reside on different platforms.
  • Self-describing data - When you look at an XML document, it is very easy to figure out what's going on.
  • Create your own languages - XML allows you to specify your own markup language for your own specific purpose. Some existing XML based languages include Banking Industry Technology Secretariat (BITS), Bank Internet Payment System (BIPS), Financial Exchange (IFX) and many more.

What Does XML Look Like?

The following example demonstrates what the contents of a typical XML document could look like.




XML Tutorial
http://www.quackit.com/xml/tutorial


HTML Tutorial
http://www.quackit.com/html/tutorial


I'll be explaining what this is all about in the coming lessons.

Difference Between XML and HTML

If you're familiar with HTML, you might notice that XML looks similar to HTML. Like XML, HTML is also a markup language. In fact, HTML stands for Hypertext Markup Language. Markup languages are used for describing how a document's contents should be interpreted.

HTML

HTML includes over 100 pre-defined tags to allow the author to specify how each piece of content should be presented to the end user. For example, if you surround some content with tags, the user agent/browser will render that content using a bold typeface.

XML

XML allows you to create your own tags to describe the data between them. You're not particularly interested in how the data will be presented. Your main focus is ensuring that the data is well organised within descriptive tags (or elements). This is because XML is primarily used for data storage and transfer purposes - not for presentation purposes.