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
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...
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. 1-Which of the following best defines a computer used as a server? a)Computer hardware that includes fast disk drives and a lot of memory b)Operating system software that includes clients, such as a Web browser and Client for Microsoft Networks c)Operating system software that includes directory services and domain name services d)A computer with Linux installed. 2-If you want...
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. 1-The technology that make up the core functionality of Windows Server 2012 include Active Directory, the Microsoft Server Manager, DHCP and IIS. Explain, in your own words, the nature and function of these technologies. Answer: 2-Windows Server Core is a new installation option in Standard, Enterprise, and Datacenter editions. The traditional Windows GUI is not available in Server Core....
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. 1-The technology that make up the core functionality of Windows Server 2012 include Active Directory, the Microsoft Server Manager, DHCP and IIS. Explain, in your own words, the nature and function of these technologies. Answer: 2-Windows Server Core is a new installation option in Standard, Enterprise, and Datacenter editions. The traditional Windows GUI is not available in Server Core....
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. 6-What are the potential disadvantages of using a dynamic and static IP Address? 7-Explain the functionality of a global catalog in the Windows networking. 8-Explain the following terms: TCP/IP protocol, and what are two command-line utilities that can be used to check TCP/IP configuration and IP connectivity, respectively? 9-Explain: Which Windows Server utility provides a common interface for tools...
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. 1-Which of the following best defines a computer used as a server? a)Computer hardware that includes fast disk drives and a lot of memory b)Operating system software that includes clients, such as a Web browser and Client for Microsoft Networks c)Operating system software that includes directory services and domain name services d)A computer with Linux installed. 2-If you want...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT