Language:

Creating a function in PHP

26 January 2011 | In Web | 1,4 thousand views | By

Click & share: 


This tip will teach you to create a simple function in PHP and how to use it. É necessário conhecimento básico de como works o sistema de variáveis do PHP e noções de HTML.

The function

Function, as the name says, executes a function in your script or system. The benefit of the function is the dynamic code is written only once and can be executed as many times as needed.

Simple function example


<?php
function dicasemgeral($url,$titulo,$destino){
$link = '<a href="'.$url.'" target="'.$destino.'">'.$titulo.'</a>';
echo $link;
}
?>

The function can be executed in any line of PHP as follows:


<?php
dicasemgeral('http://www.dicasemgeral.com/','Clique aqui e acesse o Dicas em Geral!','_blank');
?>

The example above returns the following:


<a href="http://www.dicasemgeral.com/" target="_blank">Clique aqui e acesse o Dicas em Geral!</a>

The function does not restrict the create links from variables. You can use it to do something even more dynamic. Instead of repeating lines and lines of code, consider using the functions. Você vai dar uma aliviada no seu Server e ainda descomplicará seu project!

In Ivaiporã-PR, Computer engineer, Workgroup Administrator Tips in General. Passionate about technology and Informatics.



A bit about us

    The Group generally appeared in Tips 2007 from innovative ideas on troubleshooting problems faced daily by those who use the technology and computer science, both ordinary users and technicians. But where did, why and what is the purpose of this site?

Click here to read!

Siga o Dicas em Geral no Google+

Video of the week