0% found this document useful (0 votes)
40 views

Print: by Using This Function We Can Display Outputs On Console (Screen) - This Function

The document discusses different types of tags, comments, and functions in PHP including: 1) Four tag types: universal, short, ASP, and script tags. Short tags and ASP tags need php.ini configuration to execute. 2) Single-line and multi-line comments for stopping execution. 3) Differences between echo, print and printf functions - echo doesn't return values while print does, and printf uses format specifiers. It also covers operators like assignment, arithmetic, comparison, string operators as well as combination and increment/decrement operators.

Uploaded by

ramsay21
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Print: by Using This Function We Can Display Outputs On Console (Screen) - This Function

The document discusses different types of tags, comments, and functions in PHP including: 1) Four tag types: universal, short, ASP, and script tags. Short tags and ASP tags need php.ini configuration to execute. 2) Single-line and multi-line comments for stopping execution. 3) Differences between echo, print and printf functions - echo doesn't return values while print does, and printf uses format specifiers. It also covers operators like assignment, arithmetic, comparison, string operators as well as combination and increment/decrement operators.

Uploaded by

ramsay21
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 4

22nd dec,2011 ============ 1) php script we can decalare four different types a) Universal style tag b) short open

tag c) Asp style tag d) Script style tag a) universal style tag <?php echo "universal style"; or print("universal style"); ?> b) short open tag <? echo "short open tag"; ?> c) Asp style tag <% echo "Asp style"; %> d) Script style tag <script language="php"> echo "script style"; </script> By default Wampp will not execute asp style tags and short open tags .Because php.ini we have to configuration direction related to this tags those are 1) Asp_tags , short_open_tags , the value of this tag is off by change this value to "ON" we can execute this tag. If we change the value of php.ini , php.conf direction we have to save the files then restart the web server. 2) Comments in php a) single line comment(//): to stop the execution of single line b) multi line comment(/*) : to stop the execution of multiple stmts c) Unix style comment(#): to stop the execution of on line 3) differnce between echo , print & printf functions? print: by using this function we can display outputs on console(screen). This function return a boolean value and also we cannot print multiple statements eg: <?php $x= print "welcome"; echo "<br>".$x; output: welcome ?> 1 echo: by using this function we can display outputs and we can print multiple statements at a time . It vl not return any value . where as print return boolean value Echo is faster than print eg: <?php echo "welcome","to scott","def"; ?>

printf: In printf we use format specifiers(%d,%f,%s...etc ) like in 'c' language eg: <?php printf("%s has %d cards ", "scott" ,10); ?> 4) Php operators In all programming languages, operators are used to manipulate or perform operations on variables and values. 1) Assignment Operators 2) Arithmetic Operators 3) Comparison Operators 4) String Operators 5) Combination Arithmetic & Assignment Operators 1) assignment operators: Assignment operators are used to set a variable equal to a value or set a variable to another variable's value. Such an assignment of value is done with the "=", or equal character. Example: $my_var = 4; $another_var = $my_var; Now both $my_var and $another_var contain the value 4. 2) arithmetic operators Operator Example +Addition 2+4 Subtraction 6-2 * Multiplication 5 * 3 / Division 15 / 3 %Modulus 43 % 10 example : <?php $addition = 2 + 4; $subtraction = 6 - 2; $multiplication = 5 * 3; $division = 15 / 3; $modulus = 5 % 2; echo "Perform addition: 2 + 4 = ".$addition."<br />"; echo "Perform subtraction: 6 - 2 = ".$subtraction."<br />"; echo "Perform multiplication: 5 * 3 = ".$multiplication."<br />"; echo "Perform division: 15 / 3 = ".$division."<br />"; echo "Perform modulus: 5 % 2 = " . $modulus . ". Modulus is the remainder after the division operation has been performed. In this case it was 5 / 2, which has a remainder of 1."; ?> output: Perform addition: 2 + 4 = 6 Perform subtraction: 6 - 2 = 4 Perform multiplication: 5 * 3 = 15 Perform division: 15 / 3 = 5

Perform modulus: 5 % 2 = 1. Modulus is the remainder after the division operation has been performed. In this case it was 5 / 2, which has a remainder of 1. comparison operators Comparisons are used to check the relationship between variables and/or values. If you would like to see a simple example of a comparison operator in action, check out our If Statement Lesson. Comparison operators are used inside conditional statements and evaluate to either true or false. Here are the most important 3) comparison operators: Assume: $x = 4 and $y = 5; Operator Example == Equal To $x == $y false != Not Equal To $x != $y true < Less Than $x < $y true > Greater Than $x > $y false <= Less Than or Equal To $x <= $y true >= Greater Than or Equal 2 $x >= $y false 4) string operators: As we have already seen dat the period "." is used to add two strings together, or more technically, the period is the concatenation operator for strings. example : <?php $a_string = "Hello"; $another_string = " Billy"; $new_string = $a_string . $another_string; echo $new_string . "!"; ?> output : Hello Billy! 5) combination arithmetic & assignment operators: In programming it is a very common task to have to increment a variable by some fixed amount. The most common example of this is a counter. Say you want to increment a counter by 1, you would have: $counter = $counter + 1; However, there is a shorthand for doing this. $counter += 1; This combination assignment/arithmetic operator would accomplish the same task. The downside to this combination operator is that it reduces code readability to those programmers who are not used to such an operator. Here are some examples of other common shorthand operators. In general, "+=" and "-=" are the most widely used combination operators. Operator += Plus Equals -= Minus Equals *= Multiply Equals Equivalent Operation $x += 2; $x = $x + 2; $x -= 4; $x = $x - 4; $x *= 3; $x = $x * 3; Result

/= %= .=

Divide Equals Modulo Equals Concatenate Equals

$x /= 2; $x = $x / 2; $x %= 5; $x = $x % 5; $my_str.="hello"; $my_str = $my_str . "hello";

6) pre/post-increment & pre/post-decrement: This may seem a bit absurd, but there is even a shorter shorthand for the common task of adding 1 or subtracting 1 from a variable. To add one to a variable or "increment" use the "++" operator: $x++; Which is equivalent to $x += 1; or $x = $x + 1; To subtract 1 from a variable, or "decrement" use the "--" operator: $x--; Which is equivalent to $x -= 1; or $x = $x - 1; In addition to this "shorterhand" technique, you can specify whether you want to increment before the line of code is being executed or after the line has executed. Our PHP code below will display the difference. example: <?php $x = 4; echo "The value of x with post-plusplus = " . $x++; echo "<br /> The value of x after the post-plusplus is " . $x; $x = 4; echo "<br />The value of x with with pre-plusplus = " . ++$x; echo "<br /> The value of x after the pre-plusplus is " . $x; ?> output: The value of x with post-plusplus = 4 The value of x after the post-plusplus is = 5 The value of x with with pre-plusplus = 5 The value of x after the pre-plusplus is = 5 As you can see the value of $x++ is not reflected in the echoed text because the variable is not incremented until after the line of code is executed. However, with the pre-increment "++$x" the variable does reflect the addition immediately. ==============================

You might also like