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

12ca printout

The document contains various PHP code snippets demonstrating different functionalities such as string manipulation, database operations, and function definitions. It includes examples of creating a MySQL database and table, inserting and updating records, and using PHP to output HTML content. Additionally, it showcases the use of functions to convert words to digits and manipulate strings.

Uploaded by

Durga Kanda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

12ca printout

The document contains various PHP code snippets demonstrating different functionalities such as string manipulation, database operations, and function definitions. It includes examples of creating a MySQL database and table, inserting and updating records, and using PHP to output HTML content. Additionally, it showcases the use of functions to convert words to digits and manipulate strings.

Uploaded by

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

2.

Output

4. Output
6.
<html> Output
<body>
Welcome to our school
<?php My car is blue
My dress is
echo "Welcome to our school"."<br>"; My box is
$color="blue";
echo "My car is ".$color ."<br>";
echo "My dress is ".$COLOR ."<br>"; 32:greater than 30
echo "My box is ".$coLOR ."<br>";
21:greater than 20
function trinarytest($n) 12:greater than 10
{ 4:Input a number atleast greater than 10!
$r=$n>30?"greater than 30"
:($n>20?"greater than 20"
:($n>10?"greater than 10"
:"Input a number atleast greater than 10!"));
echo $n.":".$r."\n";
}

trinarytest(32);
echo "<br>";
trinarytest(21);
echo "<br>";
trinarytest(12);
echo "<br>";
trinarytest(4);

?>

</body>
</html>
7.
<html>
<body>
<?php
$a=25;
$b="Hello";
$c=5.7;
echo "Number is : " .$a ."<br>";
echo "String is : " .$b ."<br>"; echo "Float value is : " .$c ."<br>";

$txt="INDIA"; OUTPUT
echo "I love $txt!" ."<br>";
Number is : 25
$x=2; String is : Hello
$y=2; Float value is :
echo $x+$y ."<br>"; 5.7I love
INDIA!
function mytest() 4
{ 0
tatic $a=0;echo $a; 1
$a++; 2
}
Variable x inside function is:
mytest();
echo "<br>"; Variable x outside function
mytest();
echo "<br>"; is: 2
mytest();

function demo()
{
echo "<p> Variable x inside function is: $x </p> ";
}

demo();
echo "<p> Variable x outside function is: $x </p> ";

?>
</body>
</html>
8.

<html>
<body>
<?php

// Use Echo
echo "Welcome to Tamilnadu <br>";

// Use 'print' to print on console


print "Welcome to our school! <br> ******************";

$txt1="Learn PHP";
$txt2="Daily";

$x=5;
$y=4;
echo "<h2>". $txt1. "</h2>";
echo "Study PHP \t" .$txt2. "<br>";
echo $x + $y;

$txt3="Hello";
$txt4="Welcome";

$x=7;
$y=3;
print "<h2>" .$txt3 ."</h2>";
print "Hi \t" .$txt4. "<br>";
print $x + $y;
?>
</body>
</html>
OUTPUT
Welcome to Tamilnadu
Welcome to our school!
******************

Learn PHP
Study PHP Daily
9

Hello
Hi Welcome
10
9.
<html>
<body> Output
<?php
12
echo strlen("Hello world!");
echo "<br>"; 3
echo str_word_count("Good Morning All"); emoclew
echo "<br>"; 6
echo strrev("welcome"); Hello Everyone
echo "<br>"; Good Morning!!!
echo strpos("Hello world!", "world");
PHP Tutorial
echo "<br>";
echo str_replace("Hi","Hello","Hi Everyone");
echo "<br>";

define("GREETING","Good Morning!!!");
echo GREETING;
echo "<br>";

$text='PHP Tutorial';
$text=preg_replace('/(\b[a-z])/i','<span style="color:red;">\1</span>',$text);
echo $text;

?>

</body>
</html>
10.
<html>
<body>
<?php
function word_digit($word)
{
$warr=explode(';',$word);
$result='';

foreach($warr as $value)
{
switch(trim($value))
{
case 'zero':
$result.='0';
break;
case 'one':
$result.='1';
break;
case 'two':
$result.='2';
break;
case 'three':
$result.='3';
break;
case 'four':
$result.='4';
break;
case 'five':
$result.='5';
break;
case 'six':
$result.='6';
break;
case 'seven':
$result.='7';
break;
case 'eight':
$result.='8';
break;
case 'nine':
$result.='9';
break;
}
}
return $result;
}
echo word_digit("zero;three;five;six;eight;one")."<br>";
echo word_digit("seven;zero;one")."<br>";
?>
</body>
</html>

OUTPUT

035681
701
5.
In the Wamp Server Click MySQL - > MySQL Console Window.

Enter password:

Welcome to the MySQL monitor.

1. MySQL [(none)]> create database schooldb;

1. Query OK, 1 row affected (0.29 sec)

2. MySQL['(none)']> use schooldb;

2. Database changed

3. MySQL [schooldb]> show databases;

3. Database
emd
emp
empd
employ
information_schema
mysql
schooldb

7 rows in set (0.18 sec)

4. MySQL [schooldb]> show tables;

4. Empty set (0.07 sec)


5. MySQL [schooldb]> create table student(studentid int, lastname varchar(255) ,
firstname varchar(255),address varchar(255),city varchar(255));
5. Query OK, 0 rows affected (0.77 sec)
6. MySQL [schooldb]> show tables;

Tables_in_schooldb

student

6. 1 row in set (0.00 sec)

7. MySQL [schooldb]> alter table student add(creditcardnumber varchar(25));

7. Query OK, 0 rows affected (0.51 sec)

Records: 0 Duplicates: 0 Warnings: 0

8. MySQL [schooldb]> desc student;

8.
9. MySQL [schooldb]> select *from student;

9. Empty set (0.31 sec)

10. MySQL [schooldb]> insert into


student(studentid,lastname,firstname,address,city,creditcardnumber)values(1011,"m",
"anu","rsnagar","madurai",3452522);

10. Query OK, 1 row affected (0.09 sec)

11. MySQL [schooldb]> insert into


student(studentid,lastname,firstname,address,city,creditcardnumber)values(1012,"s",
"renu","rrnagar","trichy",3452525);

11. Query OK, 1 row affected (0.08 sec)

12. MySQL [schooldb]> select *from student;

12.

13. MySQL [schooldb]> update student set lastname="m" where studentid=1012;

13. Query OK, 1 row affected (0.23 sec)

Rows matched: 1 Changed: 1 Warnings: 0


14. MySQL [schooldb]> select *from student;

14.

15. MySQL [schooldb]> drop table student;

15. Query OK, 0 rows affected (0.51 sec)

16. MySQL [schooldb]> select *from student;

16. ERROR 1146 (42S02): Table 'schooldb.student' doesn't exist

17. MySQL [schooldb]> drop database schooldb;

17. Query OK, 0 rows affected (0.07 sec)

18. MySQL [(none)]> show databases;

18.

Database
emd
emp
empd
employ
information_schema
mysql
6 rows in set (0.00 sec)

19. MySQL [(none)]> commit;

19. Query OK, 0 rows affected (0.00 sec)

You might also like