Page 294 - Computer Software Application TP - Volume 1
P. 294
COMPUTER SOFTWARE APPLICATION - CITS
<?php
$file=”info.txt”;
$content=”hai you are welcome”;
file_put_contents($file,$content) or die(“Error not opening”);
echo “Content written in the file”;
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
TASK 9: Reading characters
I Reading characters using file_get_contents function
1 Open the text editor
2 Write the following codes
<html>
<body>
<?php
$file=’my_new_file.txt’;
if(file_exists($file))
{
$content=file_get_contents($file) or die(“Error file opening not possible “);
echo $content;
}
else
{
echo “ERROR: File does not exist.”;
}
?>
</body>
</html>
279
CITS : IT & ITES - Computer Software Application - Exercise 55 CITS : IT & ITES - Computer Software Application - Exercise 55