0% found this document useful (0 votes)
16 views22 pages

OS Unit V

Operating system unit 5

Uploaded by

Dr JANANI A
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views22 pages

OS Unit V

Operating system unit 5

Uploaded by

Dr JANANI A
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Simple PHP Scripts

Using Printf

● Printf controls the format of the output by letting you put some special formatting characters
in a string.
● For each formatting character,printf excepts you to pass an argument that it will display using
that format.
● For instance the following example uses %d conversion specifier to display the value 3 in
decimal:

● if you replace %d with %b the the output will be displayed in binary


(11).
● you can also have many specifiers as you like in print function.

● the above code is valid and the output is”My name is Simson , I’m
33 years old,which is 21 in hexadecimal”.
● A more practical example of printf set colors in HTML using decimal:
Precision Setting

● PHP supports a wide variety of datatypes, including floating-point numbers.


● The precision parameter specifies the number of significant digits displayed in a
floatingpoint number representation.
● The output from this example look like this:
String Padding
● We can also padd strings for our required length,select different
padding characters,and even choose between left and right
justification.
● The output from this example look like this:
Using Sprintf
● Often you don’t want to output the result of the conversion but
need to use elsewhere in code.
● This is where sprintf function comes in.
● You can send output to another variable rather than to the browser.
Date and Time Functions
● To determine the current timestamp,you can use the time function:
● echo time();

● To obtain the timestamp for this time next week you can use the
following which adds 7 days time 24 hours times 60 minutes times
and 60 seconds to the returned value
● To display date ,date function can be used:
● The output will be “Thursday July 6th,2017-1:38pm”
Using checkdate
● This checkdate function returns value of TRUE if the date is valid
else or FALSE if it is not.
EMAIL WITH PHP
● PHP is a server-side scripting language that is enriched with various
utilities required. Mailing is one of the server-side utilities that is
required in most of the web servers today. Mailing is used for
advertisement, account recovery, subscription, etc.

● To send mails in PHP, one can use the mail() method.

● Syntax:

bool mail(to , subject , message , additional_headers , additional_parameters


● to: Specifies the email id of the recipient(s). Multiple email IDs can be passed using
commas

● subject: This contains the subject of the email. This parameter cannot contain any
newline characters.

● message: This contains the message to be sent. Each line should be separated with
an LF (\n). Lines should not exceed 70 characters (We will use wordwrap() function to
achieve this.).

● additional-headers(Optional): This is an optional parameter that can create


multiple header elements such as From (Specifies the sender), CC (Specifies the
CC/Carbon Copy recipients), BCC (Specifies the BCC/Blind Carbon Copy Recipients),
Mime-Version. Note: To add multiple header parameters one must use ‘\r\n’.

● additional-parameters(Optional): This is another optional parameter and can be


passed as an extension to the additional headers. This can specify a set of flags that
are used as the sendmail_path configuration settings.
Example:

<?php
$to = "[email protected]";
$sub = "Generic Mail";
$msg="Hello Geek! This is a generic email.";
if (mail($to,$sub,$msg))
echo "Your Mail is sent successfully.";
else
echo "Your Mail is not sent. Try Again.";
?>
● Using mail() method one can send various types of mails such as
standards, html mail.
● The mail() method opens the SMTP socket, attempts to send the
mail, and closes the socket thus is a secure option.
● mail() method should not be used for bulk mailing as it is not very
cost-efficient.
● The mail() method only checks for parameter or network failure,
thus success in the mail() method doesn’t guarantee that the
intended person will receive the mail.
EMAIL WITH ATTACHMENT
● When we are sending mail through PHP, all content in the message
will be treated as simple text only. If we put any HTML tag inside the
message body, it will not be formatted as HTML syntax. HTML tag
will be displayed as simple text.
● To format any HTML tag according to HTML syntax, we can specify
the MIME (Multipurpose Internet Mail Extension) version, content
type and character set of the message body.
● To send an attachment along with the email, we need to set the
Content-type as mixed/multipart and we have to define the text and
attachment sections within a Boundary.
EXAMPLE
OUTPUT
THANK YOU

You might also like