Question

In: Computer Science

Can you provide with examples of these PHP common functions - echo, print, filter_input, isset, empty,...

Can you provide with examples of these PHP common functions - echo, print, filter_input, isset, empty, is_numeric, include, include_once, header, htmlspecialchars, nl2br, strops(), explode(), implode(), count()

Solutions

Expert Solution

echo(), print()

<!DOCTYPE html>
<html>
<body>

<?php

echo "echo example";
echo "Hello world!<br>";

print "print Example<br>";
print "Hello world!<br>";
?>

</body>
</html>

Output:

echo example
Hello world!

print example
Hello world!

filter_input()

if (!filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL) === false) {
echo("Email is valid");
} else {
echo("Email is not valid");
}

INPUT_GET - Filter Type
"email" - Variable name to be filtered.
FILTER_VALIDATE_EMAIL - Filter type

RETURNS - false on failure and value of the variable on success, NULL if the variable is not set.

isset() , empty()

<?php
$var1 = 0;
// True because $var1 is set
if (isset($var1)) {
echo "Variable 'var1' is set.<br>";
}
// True because $var1 is empty
if (empty($var1 )) {
echo "Variable 'var1 ' is empty.<br>";
}

$var2 = null;
// False because $var2 is NULL
if (isset($var2)) {
echo "Variable 'var2' is set.";
}
?>

is_numeric()

<?php
$a = 32;
echo "a is " . is_numeric($a) . "<br>";

// RETURNS TRUE if variable is a number or a numeric string, FALSE otherwise

// Output : a is 1

?>

include , include_once

include 'filename';

Including of one php file into another we use include

include_once 'filename';

Including of one php file into another we use include_once but if the file is already included it will not include again.

header()

The header() function sends a raw HTTP header to a client.

<?php
header("Cache-Control: no-cache");
header("Pragma: no-cache");
?>

htmlspecialchars()

Convert the predefined characters "<" (less than) and ">" (greater than) to HTML entities:

<?php
$str = "This is some <b>bold</b> text.";
echo htmlspecialchars($str);
?>

// output : This is some &lt;b&gt;bold&lt;/b&gt; text.

nl2br()

Insert line breaks where newlines (\n) occur in the string:

<?php
echo nl2br("One line.\nAnother line.");
?>

Output

One line.
Another line.

strops()

Find the position of the first occurrence of "php" inside the string:

<?php
echo strpos("I love php, I love php too!","php");
?>

Output : 7

explode()

Break a string into an array:

<?php
$str = ""Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
?>

Output: Array ( [0] => Hello [1] => world. [2] => It's [3] => a [4] => beautiful [5] => day. )

implode()
Join array elements with a string:

<?php
$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr);
?>

Output : Hello World! Beautiful Day!

count()
Return the number of elements in an array:

<?php
$cars=array("car1","car2","car3");
echo count($cars);
?>

Output: 3


Related Solutions

Provide examples of PHP common functions - echo, print, filter_input, isset, empty, is_numeric, include, include_once, header,...
Provide examples of PHP common functions - echo, print, filter_input, isset, empty, is_numeric, include, include_once, header, htmlspecialchars, nl2br, strops(), explode(), implode(), count() • Remember the return values of filter_input() • Remember syntax of introduced control statements, such as if, for, foreach, while, switch, break, continue, etc. • Conceptual questions, such as − Six data types in PHP − Rules for variable names − The equality operators, such as == and === − differences between get and post methods − differences...
Can you schematically explain; 1.)Spin Echo Imaging Methods 2.) Gradient Echo Imaging Methods
Can you schematically explain; 1.)Spin Echo Imaging Methods 2.) Gradient Echo Imaging Methods
Can you provide some examples of signalling and screening in adverse selection
Can you provide some examples of signalling and screening in adverse selection
Can you give examples of using functions in real life? By real life I understand not...
Can you give examples of using functions in real life? By real life I understand not only what we do in everyday living, but also science, economy, and similar.
PLEASE EXPLAIN AS MUCH AS YOU CAN AND PROVIDE EXAMPLES TO ALL PARTS OF THE QUESTION...
PLEASE EXPLAIN AS MUCH AS YOU CAN AND PROVIDE EXAMPLES TO ALL PARTS OF THE QUESTION (THANK YOU!!!) Are elasticities likely to be larger or smaller (in absolute value) in the short relative to long run? How does this relate to the J-Curve effect?
Try to make it as simple as you can. Please provide the answers with some examples...
Try to make it as simple as you can. Please provide the answers with some examples as fast as you can. 11-Which of the following do all domains in the same forest have in common? (Choose all that apply.) a) The same domain name    b) The same schema c) The same user accounts    d) The same global catalog   12-Which of the following is a valid reason for using multiple forests? a) Centralized management     b) Need for different schemas c) Easy...
Provide two examples of social institutions that are prevalent in American society and explain their functions.
Provide two examples of social institutions that are prevalent in American society and explain their functions.
List, explain, and provide examples of 5 common errors in human inquiry.
List, explain, and provide examples of 5 common errors in human inquiry.
Can you provide some examples on how to develop an evaluation system for the Barista Job...
Can you provide some examples on how to develop an evaluation system for the Barista Job at Starbucks? Propose an evaluation system to assess the effectiveness of your recruiting and selection suggestions.
The subject is: Introduction to Healthcare Insurance Coding, Billing, and Reimbursement Can you provide examples of...
The subject is: Introduction to Healthcare Insurance Coding, Billing, and Reimbursement Can you provide examples of a charge for the following: ambulance fee schedule, ambulatory surgical center payment, clinical laboratory fee schedule, durable medical equipment prosthetics orthotics and supplies fee schedule, end-stage renal disease composite payment rate system, home health prospective payment system, hospital inpatient prospective payment system, hospital outpatient prospective payment system, inpatient psychiatric facility prospective payment system, inpatient rehabilitation facility prospective payment system, long term acute care hospital...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT