Spiga

Showing posts with label PHP. Show all posts
Showing posts with label PHP. 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/