Results 1 to 10 of 10
-
9th May 2009, 05:20 PM #1OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comPHP Tutorial ( Creating Functions ).
Heya again,
ok so this time ive decided to show you how to create functions and discuss the pros and cons of this..
A function is a block of code the performs a certain task, such predefined functions your are probably familiar with such as
- trim()
- print()
- nl2br()
but if you want to perform a task several times throught a webiste you dont wna tto have to write the code every time you need to perform it.
so functions are a way to create a block of code that is stored in the memory of php and can be called over and over again.
Heres how you create a function:
PHP Code:
/*
A function has to have the following.
1.A Name
2.Variables (if any).
to create a function the first word should be the word function and then followed by the name of the function your making
function MyFunctionName
and then followed by brackets like so
function MyFunctionName()
and then finally it should have a pair of braces like so
function MyFunctionName(){}
If we add this to a php script it will work but its useless as we have only defined a function and not done anything with it yet so lets do that now.
*/
//#1
function MyUrl(){
return 'http://www.litewarez.com';
}
#2
function MyUrl(){
echo 'http://www.litewarez.com';
}
/*
Ok so as you can see theres a difference beetween #1 and #2 ...
#1 only returns the data to the origin it was called
#2 this will print the data to the origin it was called
*/
//Lets call them
MyUrl(); // you will not see anything on your screen as #1 is returned
myUrl(); // this will print your url to the screen as you have echo'ed it within the function
/*
Its always better to return data from a functions as this allowes you to
move data around the script without any of the users seeing the data
on there screen
*/
/*
Ok so lets work with parameters.
Parameters allow you to send a string or an object directly into the function to process, below are some examples.
*/
function MakeBold($String){
return sprintf("<strong>%s</strong>",$String);
//this will replace %s with your $string
}
//Usage
$Plain_string = "I Love Litewarez.com";
$Bold_string = MakeBold($Plain_string);
//Plain_string = I Love Litewarez.com
//Bold_string = <strong>I Love Litewarez.com</strong>
Example 2.
//heres an example of performing more complex code within a function
function GetWebData($url = NULL){
if(strlen($url) < 5){
return "Url too short";
}
if(function_exists("file_get_contents")){
$Website_data = file_get_contents($url);
}else{
return "Funtion (file_get_contents) does not exists. please upgrade php";
}
if(strlen($Website_data) != 0){
return $Website_data;
}else{
return "0 Bytes of data retrieved from " . $url;
}
}
//Now you can just use this command to grab data from a website wherever
//and whenever you need to perform this task
$Grabbed_html = GetWebData("http://www.SomeSite.com");
/*
You can use this as many times as you wish and if you want to read more
about creating functions just google "Create php functions"
*/
Peacelitewarez Reviewed by litewarez on . PHP Tutorial ( Creating Functions ). Heya again, ok so this time ive decided to show you how to create functions and discuss the pros and cons of this.. A function is a block of code the performs a certain task, such predefined functions your are probably familiar with such as trim() print() nl2br() Rating: 5Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
9th May 2009, 05:58 PM #2MemberWebsite's:
Plutost.com OffshorePort.net Desi-Mobilez.com PhotoshopDesigner.co.uk TutsBy.me BabesWallpapers.netI'm soon going to learn C++ & I have heard that PHP is similar to C++
Plutost.com Asia & Europe Hosting Provider / Offshore Shared/VPS Hosting / Even Better than Gold
WHMCS License Verify (Catch those scam hosts)
Tutorials By .Me
-
9th May 2009, 08:44 PM #3OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comyes and java
Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
9th May 2009, 09:20 PM #4Member
There are tonnes of different PHP functions. Such as ip2long, stripslashes, fread & fwrite.
-
9th May 2009, 11:53 PM #5Banned
-
11th May 2009, 12:25 AM #6OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comto be honest i think before you attempt to learn new programming langs you should first understand what you want to become, for instance if you want to become a website developer then learn the following in order
*(x)HTML
*CSS
*XML
*Javascript
*PHP
*MySql
*ASP
*JAVA
But if you want to become a software engineer then you should first take a look at what OS you wish to program for i.e Windows, Linux, Mac, Other
then you should learn the architecture for the system and then learn the languages for that particular one
Personally Im a Web Developer and I have a job and a career set...
PeaceJoin Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
11th May 2009, 01:45 AM #7Respected DeveloperWebsite's:
PlatinumW.org NexusDDL.com HD-United.org CheckLinks.org FLVD.orgI personally prefer the naming convention of first letter small and others big just like javascript. Nice tut though
Current projects:
Megaupload Premium Multifetch Script | FF Plugin: Tinypic and Imagevenue Image Remoter
Projects in hiatus:
IPB Linkchecker Bot | VB Linkchecker Bot
-
12th May 2009, 12:09 PM #8OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comyea i usually write my vars and functions as HelloWorld but when im just bombing threw a quick script ill just do lowercase for speed lol
Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
12th May 2009, 12:31 PM #9MemberWebsite's:
WareztheDDL.com GTFO.wsis there any advantage of using UpperCase?
i use for javascript, but just wondering if it has advantages/disad's using it in php?
-
12th May 2009, 04:26 PM #10OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comEDITED**
with php it works as follows
1 character acts as a set amount of bytes so A and a have the exact same length and will not effect speed of your scripts
all tho if you are creating a script that others will read and edit for personal uses i would keep to industry standers and go with the flow of
lowercase first followed by lowercase until a new word then you use an uppercase to to show "visually" that there are several words.. for instance:
litewarezzoo => litewarezZoo
warezcoders => warezCoders
firstsecond => firstSecond
all tho some people tent to use _ "underscores" between words to help visability but this adds extra length to your script size and processing speeds....
peaceJoin Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Tutorial for Creating Vbulletin Theme ?
By warezrock in forum Tutorials and GuidesReplies: 7Last Post: 27th Apr 2011, 09:25 AM -
Tutorial [Creating a PHP Framework] {advanced} (PART 4)
By litewarez in forum Tutorials and GuidesReplies: 1Last Post: 9th Feb 2010, 04:24 AM -
Tutorial [Creating a PHP Framework] {advanced} (PART 1)
By litewarez in forum Tutorials and GuidesReplies: 1Last Post: 30th Jan 2010, 03:37 PM -
PHP Tutorial (Creating Classes)
By litewarez in forum Tutorials and GuidesReplies: 0Last Post: 14th May 2009, 11:40 AM -
Tutorial - Creating Signatures in Photoshop
By rich5lee in forum Tutorials and GuidesReplies: 0Last Post: 28th Jul 2008, 05:14 PM
themaCreator - create posts from...
Version 3.18 released. Open older version (or...