Write a empty file with some lines of code

Hi E's, I want write some code in a empty .html file.
I have this lines of code that I want write in the empty file:
L1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
L2 <html>
L3 <head>
L4 <TITLE>any title</TITLE>

How I do for write the empty file with the line above and respect the line numbers?

The best regards, JC
LVL 3
Pedro ChagasWebmasterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PragmatiCoderCommented:
Maybe something like:

<?php
    $data = "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n
<html>\n
<head>\n
<TITLE>any title</TITLE>\n";
    $fp = fopen("file.html", "w");
    fwrite($fp, $data);
    fclose($fp);
?>

Open in new window

0
Pedro ChagasWebmasterAuthor Commented:
Hi @PragmatiCoder, the script give me a error in line 3 (<html>\n):
Parse error: syntax error, unexpected '<' in /home/gloradin/public_html/portugal/pivot/index.php on line 3

Can you see why?

Regards, JC
0
PragmatiCoderCommented:
Ops... try:

<?php
    $data = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>\n
<html>\n
<head>\n
<TITLE>any title</TITLE>\n";
    $fp = fopen("file.html", "w");
    fwrite($fp, $data);
    fclose($fp);
?>

Open in new window

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Pedro ChagasWebmasterAuthor Commented:
Hi, what kind of permission I have to give?
I get this warning:
Warning: fopen(file.html) [function.fopen]: failed to open stream: Permission denied in /home/gloradin/public_html/portugal/pivot/index.php on line 6

Warning: fwrite(): supplied argument is not a valid stream resource in /home/gloradin/public_html/portugal/pivot/index.php on line 7

Warning: fclose(): supplied argument is not a valid stream resource in /home/gloradin/public_html/portugal/pivot/index.php on line 8

I have to change the CHMOD of the folder where I save the files, or I have to change the CHMOD of the files file.html?

Regards, JC
0
PragmatiCoderCommented:
You have to change the permissions on the folder you are trying to write to (chmod 777)
0
Pedro ChagasWebmasterAuthor Commented:
About the permission I try to change the CHMOD of folder and don't work, and I change the permission of the file.html and work well.

Just for finish, and if it is possible and simple, I like to fix a little problem, that was:
L1 appear in Line 1
L2 appear in line 4
L3 appear in line 7
L4 appear in line 10

In practice your solution give me the lines, 2, 3, 5, 6, 8 and 9 empty.

Have any simply way to resolve this little issue?

Regards, JC
0
PragmatiCoderCommented:
hmmm... that's weird...

Try this:

<?php
    $data = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>\n<html>\n<head>\n<TITLE>any itle</TITLE>\n";
    $fp = fopen("file.html", "w");
    fwrite($fp, $data);
    fclose($fp);
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.