Showing posts with label PHP print. Show all posts
Showing posts with label PHP print. Show all posts

Monday, 5 August 2019

PHP tutorial: Constant and echo-print statement

Constant  and echo-print statement

Constants:
1) A constant is a name or an identifier for a simple value. It is defined using the define function and it does not start with $ sign
define(“DBNAME”, TECH);
2) A constant value cannot change during the execution of the script. By default, a constant is case-sensitive. By convention, constant identifiers are always uppercase. A constant name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. If you have defined a constant, it can never be changed or undefined.
3) A constant differ from variable as variable value can be changed across the execution while constant value cannot
4) Constant value are global across the execution.
5) constant value are retrived using constant() function or simlying we can use echo
<?php
echo “DBNAME”;
echo “constant(DBNAME);
?>
6) PHP defined some predefined constants like _LINE_,_FILE_, _CLASS_
Print/echo statement
1) Print /echo does the same job i.e printing the statement on the screen
example
<?php
print “This is php script”;
echo ” This is php script”;
?>
2) It print the variable name in the same manner as given below
<?php
$x=10
print “This is $x”;
echo ” This is $x”;
?>
This is 10
This is 10
3) The behavior with single quotes is different
<?php
$x=10
print ‘This is $x’;
echo “This is $x”;
?>

Monday, 2 February 2015

Format Debugging Messages

Format Debugging Messages

<?php
function debug( $line, $msg ){
    static 
$calls = 1;
    print 
"<P><HR><br>\n";
    print 
"DEBUG $calls: Line $line: $msg<br>";
    
$args = func_get_args();
    
    if (  
count( $args ) % 2 )
        print 
"Odd number of args<BR>";
    else{
        for ( 
$x=2; $x< count($args); $x += 2 ){
            print 
"&nbsp&nbsp; \$$args[$x]: ".$args[$x+1];
            print 
" .... (".gettype( $args[$x+1] ).")<BR>\n";
        }
    }
    print 
"<hr><p></p>\n";
    
$calls++;
}
$test = 55;debug( __LINE__, "First message", "test", $test );$test = 66;$test2 = $test/2;debug( __LINE__, "Second message", "test", $test, "test2", $test2 );?>

What's the difference between PHP echo() and PHP print()?

What's the difference between PHP echo() and PHP print()? 

<?php
     
print "Hello World! <br />";
     echo 
"Hello World! <br />";
     
// The above outputs the text "Hello World!" on two separate lines.
     // Notice they are identical in output!

     
print ("Hello World! <br />");
     echo (
"Hello World! <br />");
     
// The above are just the same, with parenthesis.
     // Notice both can act like functions, but note they actually aren't.
?>


In all actuality, Echo and Print differ based on how they are structured. Print returns a value much like a normal function would. But despite common belief, Print is not a function, as we can see by the fact that it doesn’t require parenthesis to work (Not to be confused with Printf). Print and Echo are actually both called language constructs, although this isn’t to say that we can’t make Print act like a function.

PHP Echo Vs Print: Which Is Faster?

Echo is faster than print. 

Print can be used as part of complex constructs, such as
($b) ? print “True” : print “False”; // or echo ($b ? “true” : “false”);
Also, if you want to use error output (@print”Test”;)
Print is easy because almost every language use it. but most php developers use echo because it is faster and it is sounds cool!

PHP Print and Echo both output data to the screen in a same pattern but PHP Echo and PHP Print differ based on how they are structured.

In PHP, echo is not a function but a language construct. In PHP, print is not a really function but a language construct. However, it behaves like a function in that it returns a value. 

The echo() function is slightly faster than print(). With echo you can send a string of text.
The print() function outputs one or more strings. 



Monday, 29 September 2014

print in PHP

 PHP print() function is utilized to print a output string.

It can output all types of information and various outputs could be made with a single print() order.

Syntax:

print(strings)
strings : Required.One or more strings for output.

Tip : The print() function is somewhat slower than echo().

Example:

<?php
print 'Good Morning!'.'<br />';
$my_name = "Jack.";
print "My name is $my_name"."<br />";
?>
Output will be:
Good Morning!
My name is Jack.