30 September 2013

What are the difference between echo() and print() in PHP ?

  • To better understand the difference, you have to know the syntax with example of echo() and print(). Syntax of echo() :
void echo ( string $arg1 [, string $... ] )

  • Example of echo():
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<?php

    echo ("The quick brown fox.");

    echo "The quick brown fox.";

    $dept_name="HR";

    echo "My department name is :$dept_name";

    echo"<p>

    Another message 1 Another message 2

    Another message 3

    </p>";

    ?>

  • Syntax of print()
int print ( string $arg )

  • Example of print():
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
    <?php

    print("The quick brown fox.");

    print "The quick brown fox.";

    $dept_name="HR";

    print "My department name is :$dept_name";

    print"<p>

    Another message 1 Another message 2

    Another message 3

    </p>";

    ?>

  • echo() is used to output one or more strings print() is used to output a string. 
  • Both echo() and print() are not actually a real function, it is a language construct. 
  • So you are not required to use parentheses with its argument list. 
  • echo() can take more than one parameter when used without parentheses. 
  • print() only takes one parameter. 
  • echo() is not a real function ,so it does not return any value. Though print() is also not a real function, but it will always returns 1. 
  • echo() has a shortcut syntax, this short syntax only works if the short_open_tag configuration setting on php.ini is enabled. 
  • Example of short_open_tag:
1
2
3
4
5
6
7
<?php

    $blog_address="http://shafiq2410.wordpress.com/";

    ?>

    <p>My Blog address is: <a href="<?=$blog_address?>" target="_blank"><?=$blog_address?></a></p>

PHP & MySQL: Novice to Ninja: Get Up to Speed With PHP the Easy Way

How to Comment your code in PHP?

  • PHP supports 'C', 'C++' and Unix shell-style (Perl style) comments. 
  • You may use any style based on your requirements. 
  • Single-Line code comments use C++ Syntax 
  • Multiple-Line code comments use C Syntax 
  • Unix Shell Syntax (Perl Style) is also used for single line comments 
  • Example: Single-Line C++ Syntax
1
2
3
4
5
6
7
 <?php

        // Title: My first PHP code

          echo "This is a PHP program.";

    ?>
  • Example: Unix Shell Syntax
1
2
3
4
5
6
7
 <?php

       # Title: My first PHP code

          echo "This is a PHP program.";

    ?>
  • Example: Multiple-Line C Syntax
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<?php

    /*

    Title: Test Code

    Author: shafiq

    Author URL: http://shafiq2410.wordpress.com

    Email: shafiq2410@gmail.com

    */

    echo "This is a PHP program.";

    ?>
PHP Cookbook: Solutions & Examples for PHP Programmers

29 September 2013

How does code is separated in PHP?

  • PHP requires instructions to be terminated with a semicolon at the end of each statement. 
  • The closing tag (?>) of a block of PHP code automatically implies a semicolon(;) 
  • (Ref-Example 2), so you do not need to have a semicolon terminating the last line of a PHP block.
  • Example 1:
1
2
3
4
5
6
7
<?php

        echo 'This is a test';

        echo 'This is another test';

    ?>
  • Example 2:
1
<?php echo 'This is a test' ?>
  • Example 3:
1
<?php echo 'We omitted the last closing tag'; 
  • Note: The closing tag of a PHP block at the end of a file is optional and in some cases omitting it is helpful when using include() or require(), 
  • So unwanted white space will not occur at the end of files, and you will still be able to add headers to the response later.
Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5 (Learning PHP, MYSQL, Javascript, CSS & HTML5)

What are the Syntax of PHP programming language

  • When PHP parses a file, it looks for opening PHP tag "<?php or <?" and ending php tag " ?>" which tell PHP to start and stop interpreting the code between them. 
  • Everything outside of a pair of opening and closing tags is ignored by the PHP parser. Example:
1
2
3
4
5
 <p>This is going to be ignored by PHP Parser.</p>

        <?php echo 'While this is going to be parsed.'; ?>

    <p>This will also be ignored by PHP parser.</p>
  • PHP code must have a semicolon ";" at the end of each statement.
  • The closing PHP tag "?>" automatically insert a semicolon.
  • Example:
  • 1
    2
    3
    4
    5
    6
    7
    <?php
        echo 'PHP is Fun to learn !!';
    ?>
    <br>
    <?php  echo 'PHP automatically insert a semicolon at the last closing tag' ?>
    <br>
    <?php echo 'If a PHP file have only PHP code than the last closing tag can be omitted';
    
  • Example Advanced escaping
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
<?php

        if ($expression) {

        ?>

        <strong>This is true.</strong>

        <?php

        } else {

        ?>

        <strong>This is false.</strong>

        <?php

        }

        ?> 
  • Before PHP version 7 There were four different pairs of opening and closing tags which could be used in PHP. Standard tag is always available Example: Script tag is also always available Example:
1
2
3
<script language="php">echo 'some editors (like FrontPage) don\'t like processing instructions';

            </script>
  • Short tags can be turned on and off from the php.ini configuration file. Example:
1
<?= expression ?>
  • This is a shortcut for
1
<? echo expression ?>
  • ASP style tags can be turned on and off from the php.ini configuration file Example:
1
<% echo 'You may optionally use ASP-style tags'; %><%= $variable; # This is a shortcut for "<% echo . . ." %>

PHP for the Web: Visual QuickStart Guide (5th Edition)

10 September 2013

Solution of Joomla 3.5 authentication error: Warning JAuthentication: :__construct: Could not load authentication libraries.


joomla login
joomla login


  • The solution steps are given bellow:
  •   Step1: connect your Joomla database with any database tools like phpMyadmin or Navicat for MySQL, I personally like to use Navicat.
 
  • Step2:  Find the tabprefix _extensions table in my case it’s” ybgvu_extensions” & brows for data on that table.
 
  • Step3: Find for the name ”plg_authentication_joomla” & change the enable column value from 0 to 1 & save the change.


JOOMLA tabprefix _extensions
tabprefix _extensions


  • Step 4: It’s done. Now you can login to your Joomla website using your existing username & password.
Joomla Administration panel
Joomla Administration panel

Joomla! Bible

02 September 2013

How to Change Password in Oracle using Oracle SQL developer ?

If want to change the old password of your oracle database user, then you can easily do it by the following SQL command: SQL Command Syntax:

1
ALTER user user_name identified by new_password replace old_password;

Example: Let, existing oracle user name = shafiq & password=abc123, then you to change the password of shafiq user, the correct SQL command is:

1
2
3
4
5
ALTER user shafiq

IDENTIFIED by "new_password123"

REPLACE "abc123";

Type the command on you SQL developer command SQL Worksheet or any other Database Tools you currently use.

Change Password in Oracle using Oracle SQL developer
Change password in oracle

Oracle SQL Developer Handbook (Oracle Press)

01 September 2013

Difference between the break and continue in programming language


BREAK
Break
 The break statement will terminate iteration of the loop and continue executing if there is any code that follows after the loop. Example of Break statement in JavaScript:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<script>

x=0;

for(x=0;x<10;x++)
{
if(x==3)
{
break;    
}
document.writeln("x=" + x + "<br />");

}


</script>
Output: x=0 x=1 x=2

Continue
Continue

The continue statement will terminate the current execution of loop and resume the loop with the next value if any. Example of Continue statement in JavaScript:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<script>

xx=0;

for(xx=0;xx<5;xx++)
{
if(xx==3) 
{
continue;
}
document.writeln("xx=" + xx + "<br />");
}

</script>
Output: xx=0 xx=1 xx=2 xx=4
Beginning Programming All-In-One Desk Reference For Dummies

Featured Post

How to Write PHP code and HTML code within a same file

A PHP file can have both PHP code and HTML code together. Any HTML code written outside of PHP <?php //php code here… ?> Code is ig...

Popular Posts