PHP Web Development Tips - iprismtech.com - PowerPoint PPT Presentation

About This Presentation
Title:

PHP Web Development Tips - iprismtech.com

Description:

iPrism Technologies is fastest growing Web Development and Mobile App Development Company. We provide you best mobile app’s and development services to your business in affordable prices. For any other information contact this no: +918885617929. – PowerPoint PPT presentation

Number of Views:16

less

Transcript and Presenter's Notes

Title: PHP Web Development Tips - iprismtech.com


1
PHP Web Development Tips
  • www.iprismtech.com

2
PHP Web Development Tips
PHP is a script language and interpreter that is
freely available and used primarily on Linux Web
servers. PHP, originally derived from Personal
Home Page Tools, now stands for PHP Hypertext
Preprocessor, which the PHP FAQ describes as a
recursive acronym. PHP is an alternative to
Microsoft's Active Server Page (ASP) technology.
As with ASP, the PHP script is embedded within a
Web page along with its HTML. Before the page is
sent to a user that has requested it, the Web
server calls PHP to interpret and perform the
operations called for in the PHP script. Web
Development Tips for PHP echo() vs.
print() Even both of these output mechanism are
language constructs, if you benchmark the two you
will quickly discover that print() is slower then
echo(). The reason for that is quite simple,
print function will return a status indicating if
it was successful or not (note it does not
return the size of the string), while echo simply
print the text and nothing more. Since in most
cases this status is not necessary and is almost
never used it is pointless and simply adds
unnecessary overhead. echo( 'Hello World' ) //
is better than print( 'Hello World' )
3
PHP Web Development Tips
Avoid the use of printf Using printf() is slow
for multitude of reasons and I would strongly
discourage it's usage unless you absolutely need
to use the functionality this function offers.
Unlike print and echo printf() is a function with
associated function execution overhead. More over
printf() is designed to support various
formatting schemes that for the most part are not
needed in a language that is typeless and will
automatically do the necessary type conversions.
To handle formatting printf() needs to scan the
specified string for special formatting code that
are to be replaced with variables. As you can
probably imagine that is quite slow and rather
inefficient. echo 'Result', result // is
better than printf( "Result s", result )
4
PHP Web Development Tips
Single quotes vs. double quotes In PHP there is
a difference when using either single or double
quotes, either or . If you use double quotes
then you are telling the code to check for a
variable. If you are using single quotes then
you are telling it to print whatever is between
them. This might seem a bit trivial, but if you
use the double quotes instead of the single
quotes, it will still output correctly, but you
will be wasting processing time. echo 'Result '
. var // is better than echo "Result
var" Even the use of sprintf instead of
variables contained in double quotes, its about
10x faster.
5
PHP Web Development Tips
Avoid functions inside loops Try to use
functions outside loops. Otherwise the function
may get called each time. // e.g. In PHP for
loop with a count() inside the control // block
will be executed on EVERY loop iteration. max
count( array ) for( i 0 i lt max i )
// do something // is better
than for( i 0 i lt count( array ) i
) // do something It's even faster
if you eliminate the call to count() AND the
explicit use of the counter by using a foreach
loop in place of the for loop. foreach (array as
i) // do something
6
PHP Web Development Tips
Use the braces PHP is probably one programming
language that makes extensive use of the flow
control loops and the if else statements,
therefore, it becomes an absolute necessity to
maintain clarity and readability in the code.
Using braces makes your code less congested and
minimizes the possibilities of errors. Eg Wrong
Way lt?php if (agelt18) echo 'You
are not an adult yet' ageage 1
echo 'Next Year you will be an adult'
else echo 'You are an adult' ?gt
7
PHP Web Development Tips
In the above example, not using the curly braces
forces the code to print Next year you will be
years old at all times, while actually it should
have only been printed when the if condition was
true. Right Way lt?php age18 if
(agelt20) echo 'You are not an adult
yet' age age 1 echo
'Next Year you will be '.age.' years old'
else echo 'You are not an adult'
?gt
8
PHP Web Development Tips
Use PHPs inbuilt functions PHP provides
developers with highly useful inbuilt functions
that can save both time and cost for the project.
It is a good practice to use the PHP in built
functions for the operations that otherwise take
a lot of time and eat up a lot of lines due to
the use of loops.Eg lt?php integers
array(10,12,4,87,55) sort(integers) ?gt The
values stored inside the array variable
integers are numeric in nature and the sort()
function will arrange the values inside the array
variable integers in ascending numerical order.
9
PHP Web Development Tips
Visit www.iprismtech.com Whatsapp/Call
8885617929 Like facebook.com/iprismtech Tweet
Twitter.com/iprismtech
10
PHP Web Development Tips
Thank You For Watching
Write a Comment
User Comments (0)
About PowerShow.com