Post on 01-Apr-2015
transcript
CREATED BY : VIRAL M.KORADIYA
<a> </a>
Anchor elements are defined by the <a> element. The <a> element accepts several attributes, but either the Name or HREF attribute is required.
Attribute HREFNAMETARGET
The href Attribute
if the HREF (Hypertext Reference) attribute is present, the text between the opening and closing anchor elements becomes a hypertext link.
Example:<a href =“abc.html”> link </a>
The target Attribute
The target attribute defines where the linked document will be opened.
Example:
<a href="http://www.google.com/"target="_blank">Visit Google!</a>
The name AttributeWhen the name attribute is used, the <a> element defines a named anchor inside a HTML document.
Named anchor are not displayed in any special way. They are invisible to the reader.
Named anchor syntax:<a name="label">Any content</a> The link syntax to a named anchor: <a href="#label">Any content</a>
Example:
A named anchor inside an HTML document:<a name="tips">Useful Tips Section</a>
A link to the Useful Tips Section from the same document:
<a href="#tips">Jump to the Useful Tips Section</a>
Line Breaks<BR><HR>
<BR> The line break element specifies that a new
line must be started at the given point.
<HR> A horizontal rule(<HR>) element is a divider
between sections of text, such as a full-width horizontal rule or a similar graphic.
Attribute:<hr align=left><hr align=right><hr align=center><hr color=name><hr size=value><hr width=number\percent><hr noshade>
<HTML><HEAD> <TITLE></TITLE></HEAD><BODY></BODY></HTML>
Document Tag<HTML> </HTML><HEAD> </HEAD><BODY> </BODY><TITLE> </TITLE><!-- --> comment
Body TagAttribute
bgcolor Example <body bgcolor=red>
Text Example <body text=blue>
Comment<html> <head> <title> Example of comment</title> </head> <body> hello <!– this is comment -- > </body> </html>
Text Formatting Tag<H1> </H1> to <H6> </H6><P> </P><Pre> </Pre><B> </B><U> </U><I> </I><Tt> </Tt><Strike> </Strike><Sub> </Sub>
<Sup> </Sup><Big> </Big><Base><Strong> </Strong><Small> </Small><Font> </Font><Basefont> <Basefont><Blink><Marquee>
<H1> </H1> to <H6> </H6>HTML defines six levels of heading<H1> </H1><H2> </H2><H3> </H3><H4> </H4><H5> </H5><H6> </H6>
<P> </P>
The paragraph element indicates a paragraph of text.
To align paragraph use ALIGN =left/right/center attribute and values have been added to the <p> element.
<p align=left><p align=right><p align=center>
<Pre> </Pre>The preformatted text element presents blocks
of text in fixed-width font and is suitable for text that has been formatted on-screen or in a mono-spaced font.
<B> </B>This tag is specified text should be bold
<U> </U>• This tag is specified text should be
underline.
<i> </i>This tag is specified text should be Italic
style.
<TT> </TT>
• The TeleType element specified that the text be rendered in fixed-width typewriter font where available.
<Strike> </Strike>The <strike> </strike> element states that the
enclosed text should be displayed with a horizontal line striking through the text.
<Sub> </Sub>The <Sub> element specifies that the
enclosed text should be displayed as a subscript.
<Sup> </Sup>
• The <Sup> element specifies that the enclosed text should be displayed as a superscript.
<Big> </Big>The <Big> element specifies that the
enclosed text should be displayed, if practical, using a big font compared with the current font.
<Strong> </Strong>The strong element can be used to indicate
strong typographic.
<Small> </Small>
• The <Small> element specifies that the enclosed text should be displayed, if practical, using a small font compared with current font.
<Base>The <base> tag specifies a default address or a
default target for all links on a page.The <base> tag goes inside the head element.Attribute :-HREF Example:<head><base href="D:\\"><body>
Microsoft internet explorer support different-sized fonts within HTML documents.The element is <font size=value>. Valid values range from 1 to 7. the default font size is 3.
Font attributesSize : 1 to 7Color : color name & #rrggbb The color attribute sets the color that text
appears on screen. #rrggbb is a hexadecimal color denoting an RGB color values.
Face : name The face attribute sets the typeface used to
display the text on-screen. The typeface displayed already must be installed on the user’s computer.
Example<font size =5> hello </font> or <font color=red> hello </font> or <font color=#ff0000> hello </font><font face=“Courier New”> hello </font>
<basefont>The <basefont> tag specifies a default font-
color, font-size, or font-family for all the text in a document.
Example: <head> <basefont color="red" size="5"> </head>
<Blink>
Surrounding any text with this element causes the selected text to blink on the viewing page. This can add extra emphasis to selected text.
Example<blink> this text blink on the page </blink>
Note: the <blink>…</blink> element currently is supported only by Netscape browser.
<Marquee> </Marquee>
The <marquee> element allows you to create a region of text that can be made to scroll across the screen.
Example:<marquee> Hello student </marquee>
AttributesAlign
This attribute can be set to TOP,MIDDLE and BOTTOM specifies that the text around the marquee should align with the top, middle and bottom of the marquee.
Example: <marquee align=top> hello </marquee>
Behavior
This can be set to SCROLL, SLIDE and ALTERNATE. It specifies how the text displayed in the marquee should behave.
Example:<marquee behavior=alternate>hello</marquee><marquee behavior=scroll>hello</marquee><marquee behavior=slide>hello</marquee>
Direction This specifies in which direction the
<marquee> text should scroll. The default is LEFT. Which means that the text will scroll to the left from the right-hand side of the marquee. This attribute also set to RIGHT, which causes the marquee text to scroll from the left to the right.
Example: <marquee direction=right>hello</marquee>
FramesWith frames, you can display more than one HTML document in the same browser window. Each HTML document is called a frame, and each frame is independent of the others.
The disadvantages of using frames are:
The web developer must keep track of more HTML documents It is difficult to print the entire page
The Frameset Tag
The <frameset> tag defines how to divide the window into frames
Each frameset defines a set of rows or columns
The values of the rows/columns indicate the amount of screen area each row/column will occupy
The Frame Tag
The <frame> tag defines what HTML document to put into each frame
<frameset cols="25%,75%"> <frame src="frame_a.htm"> <frame src="frame_b.htm"></frameset>
In the example below we have a frameset with two columns. The first column is set to 25% of the width of the browser window. The second column is set to 75% of the width of the browser window. The HTML document "frame_a.htm" is put into the first column, and the HTML document "frame_b.htm" is put into the second column:
<frameset> Tag
Definition and Usage
The <frameset> tag defines a frameset.The frameset element holds two or more frame
elements. Each frame element holds a separate document.
The frameset element states only how many columns or rows there will be in the frameset.
ExampleA simple three-framed page:<html>
<frameset cols="25%,*,25%"> <frame src="frame_a.htm" /> <frame src="frame_b.htm" /> <frame src="frame_c.htm" /></frameset>
</html>
Attributes COLS = PIXELS OR PERCENTAGESpecifies the number and size of columns in a
frameset
ROWS = PIXELS OR PERCENTAGESpecifies the number and size of rows in a
frameset
Vertical Frame<html>
<frameset cols="25%,50%,25%">
<frame src="frame_a.htm"> <frame src="frame_b.htm"> <frame src="frame_c.htm">
</frameset>
Horizontal Frame<html>
<frameset rows="25%,50%,25%">
<frame src="frame_a.htm"> <frame src="frame_b.htm"> <frame src="frame_c.htm"> </frameset>
<IMG>……..</IMG><AREA>……</AREA><MAP>………</MAP>
The <img> tag embeds an image in an HTML page.
Notice that images are not technically inserted into an HTML page, images are linked to HTML pages. The <img> tag creates a holding space for the referenced image.
The <img> tag has two required attributes: src and alt.
Required Attributes
Attribute Value Description alt text Specifies an alternate text for an image
src URL Specifies the URL of an image
Example:
<html><body><img src="D:\i.jpg.jpg"><img src="" alt="image is note display">
</body></html>
Optional Attributes
Align : Use styles instead Specifies the alignment of an image according to surrounding elements Values : left ,right
<img src="D:\image1.jpg" align ="right">
Border: Specifies the width of the border around an image Value: pixels
Height : Specifies the height of an image Value: pixels %
Width :Specifies the width of an image Value : pixels %
vspace: Specifies the whitespace on top and bottom of
an image Value: pixel
hspace: Specifies the whitespace on left and right side of
an image Value : pixel
Example:<html><body><img src="D:\image2.jpg" border=15><img src="D:\image3.jpg" width=250 height=500 ><img src="D:\image4.jpg" hspace="200“ vspace="1000"> </body></html>
Table HTML Elements are:
<TABLE>…………….</TABLE><CAPTION>…………</CAPTION><TH>………………….</TH><TR>………………….</TR><TD>………………….</TD>
TABLE ATTRIBUTE:ALIGN =LEFT, RIGHT, CENTERBGCOLOR=“#RRGGBB /COLORNAME”BORDER =VALUEBORDERCOLOR=“#RRGGBB /COLORNAME”CELLPANDDING=VALUECELLSPACING=VALUEHEIGHT= PERCENTWIDTH= PERCENTBACKGROUND= IMAGE
CAPTION ATTRIBUTESALIGN ATTRIBUTE
ALIGN=LEFTALIGN=RIGHTALIGN=CENTERALIGN=TOPALIGN=BOTTOM
<TR>,<TH>,<TD> ATTRIBUTES
ALIGN=LEFT / RIGHT / CENTERBACKGROUND=IMAGEBGCOLOR=“#RRGGBB”/COLORNAMEBORDERCOLOR =“#RRGGBB”/COLORNAMECOLSPAN=VALUEROWSPAN=VALUEHEIGHT=PERCENTWIDTH=PERCENTNOWRAP
TopicsBackground and History of PHPInstallationComments in PHPVariablesConditionsLoopsFunctionsFile HandlingDatabase Handling (MySQL, MSSQL,
ODBC)
BackgroundPersonal Home Page – C kind of scripts
written in Perl language, by Rasmus Lerdorf in 1995.
He called the language as PHP/FI – Personal Home Page / Forms Interpreter.
1997 Version 2.0 was releasedThen came 3.0, 4.0. They were called PHP
simplyRecent version is PHP 5.2.3
InstallationApache server need to be installed firstThe config file for apache server will be
present in the conf folder under the apache installed directory
Set the DocumentRoot to the path where the PHP files will be stored
Install PHP. Point apache conf directory when it asks so and select the appropriate web server.
Move the PHP.ini file to C:\WNDOWS directory
PHP CommentsAll php files are saved with extension .phpThe can be written in notepad or any text
editorSingle line comment
// this is single line commentMulti line comment
/*….This is a multi line comment */
Sample PHP<html><body><?php echo “hello”; ?></html>
The above program will display hello in the browser
VariablesVariables start with a $ symbolVariables can contain _ or numbers or
alphabets$ should be followed by _ or alphabet and not
by a numberPHP is loosely typed language. There is no
strict data typingVariable can be assigned with any values
Conditions If else
if(condn) {….}elseif(condn) {….}else { ….}
Switch caseswitch(var){case c1: statements;break..Default: statements; break;}
LoopsFor
for(intialisation;condition;increment/decrement){ statements }
While while(condn) { ….}
Do Whiledo {….} while(condn);
Functions and ParametersPHP functions need to be defined with key
word functionIt can have zero or more values (parameters)Functions may or may not return valuesIf a function need to return value, the last
statement of the function should be returnreturn value;
FunctionsParameter less function
<?php function sayHi(){
echo “hi”;}?> This can be called as <?php sayHi(); ?> in the
program
FunctionsParameterized function<?php function greet($name){
echo “Hello “ . $name;}?>This can be called <?php greet(‘Ram’);?> This gives an output Hello Ram
FunctionsFunction returning value<?phpfunction add($a,$b){
return ($a + $b);}?> When called like <?php echo add(1,2);?>
we will get an output 3 in the browser.
File HandlingThis involves 5 tasks
Opening a fileReading data from a fileDisplaying the read dataWriting contents to another fileClosing a file
Opening a file$fp = fopen(‘filename’,’mode’);Eg $fp = fopen(‘c:\abc.txt’,’r’);
This opens a file abc.txt in read only modeAvailable modes:
r – read onlyw – write onlyw+ - read writeA – append – adding to the end
Reading a fileSeveral methods are available
fread(filepointer,no of bytes to read)fgetc(filepointer) – Reads character by characterfgets(filepointer) – Reads line by line
The read content can be stored in a variable$data = fread($fp,10) – this reads 10
characters from file pointed by file pointer $fp and stores in $data
If we want to read characters till end, we need to use a loop with condition checking for End of File
Writing to fileWe can use echo $data, to print the
contents read from the file to browserOr we can open another file in write mode
and put the contents to that file using either of these methodsfwrite(filepoiner,data);fputc(filepointer,char); - writes character by
characterfputs(filepointer,line); - writes line by line
Eg - fwrite($fpw,$data);
Closing a filefeof(fp) – Checks for end of file. Returns –1 if EOF is reached. Otherwise
returns 0To close a file use fclose(filepointer) methodEg. fclose($fp);
This closes the file pointed by $fp.
Database HandlingPHP can connect to
MySQLMSSQLAccess and other databases like oracle, postgre
sql etcThere are separate methods available for
connecting to the databases
MySQL and MSSQL Connectionmysql_connect(dbserver,userid,password)mssql_connect(dbserver,userid,password)
These methods are used for connecting to MySQL and MSSQL server using a userid and password
$con = mysql_connect(‘localhost’,’root’,’root’);This gets a connection to the local mysql server
using the credentials root and rootIf server cannot be connected, it will throw an
error stating the problemNote: Mysql and MSSQL can be accessed in
identical way except for the preceeding mysql or mssql. So will use mysql henceforth.
MySQL Select DBmysql_select_db(connection,dbname)
mysql_select_db($con,”test”);This will select the db test under the server localhost
If unable to select the database, an error will be thrown
MySQL Execute Querymysql_query(connection,sql statement);This will execute the sql statement on the
database and store the result in a variableEg
$rs = mysql_query($con,select stmt);The rows of select statement will be stored in $rs$row = mysql_fetch_array($rs);
This will fetch a row and store in $row Values can be accessed like - $row[“ID”] – returns value
of column ID in the fetched row.
MySQL and MSSQL CloseTo close a db connection we have close
methodmysql_close(connection);mssql_close(connection);
Examplemysql_close($con);mssql_close($con);
ODBC Data handlingConnect to a data source
odbc_connect(dsn,uname,pwd);DSN – Data Source NameGo to Control Panel -> Administrative Tools ->
Datasources (ODBC)Click on ODBC and select System DSN tab.Click Add and choose Access Database (mdb)
and click FinishIn the dialog that appears, give DSN Name and
Description
ODBC Data handling Contd..
Click on Select under Database sectionChoose a mdb (access database file) and give
OK
$conn=odbc_connect('nwind','','');Here nwind is the DSN that we have created in
our system to access a databaseWe have not given any user name or password
during DSN creationSo those fields are left empty.
Selecting rows from a table$rs = odbc_exec($conn,$sql);
$conn – connection string$sql – SQL query to select rows from table$rs is the result set of the query execution
odbc_fetch_row($rs)This command fetches row by row from the result
set$cid = odbc_result($rs,"CustomerID");
This command fetches value for the column CustomerID from the current row and stores it in the variable $cid.
Closing Connectionodbc_close(connection)
This function closes the connection obtained and releases the same to the connection pool
odbc_close($conn);The connection defined by $conn is released
and no query can be executed using this connection variable hence forth.