Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Write a empty file with some lines of code

Posted on 2011-10-04
7
Medium Priority
?
378 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:Pedro Chagas
  • 4
  • 3
7 Comments
 
LVL 5

Expert Comment

by:PragmatiCoder
ID: 36913898
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
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 36913989
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
 
LVL 5

Expert Comment

by:PragmatiCoder
ID: 36913993
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Author Comment

by:Pedro Chagas
ID: 36914023
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
 
LVL 5

Expert Comment

by:PragmatiCoder
ID: 36914045
You have to change the permissions on the folder you are trying to write to (chmod 777)
0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 36914124
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
 
LVL 5

Accepted Solution

by:
PragmatiCoder earned 2000 total points
ID: 36914132
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question