Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Please help with fwrite and fopen. Thanks
Old 10-02-2008, 06:45 PM Please help with fwrite and fopen. Thanks
michiganannd's Avatar
Average Talker

Posts: 22
Trades: 0
Hi; I'm a newbie. Im trying to do this code:
PHP Code:
                      <?php
$vidlink 
'http://www.yourdomain.com/';
$str=file_get_contents($vidlink);
$fulltype '.html';
$b "1";
$filename $b.$fulltype;
file_put_contents($b.$fulltype$str);    
chmod($filename0777);
$somecontent "\nSomething here\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

    if (!
$handle fopen($filename'r+')) {
         echo 
"Cannot open file ($filename)";
         exit;
    }

    
// Write $somecontent to our opened file.
    
if (fwrite($handle$somecontent) === FALSE) {
        echo 
"Cannot write to file ($filename)";
        exit;
    }

    echo 
"Success";

    
fclose($handle);

} else {
    echo 
"The file $filename is not writable";
}
?>

I want to add a content in the beginning of the page but it always cut down the


Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
and it appears as

Code:
    My new content TML 4.01 Transitional//EN"> 
thats why the page is broken...
Can you please help me so it doesnt cut down the first doctype of the page when i add a new content.

Thanks in advance

P/s: seems like it always overwrite the doctype line... if i try to write it at the bottom of the page then it is fine.
__________________

Please login or register to view this content. Registration is FREE
michiganannd is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-15-2008, 03:21 AM Re: Please help with fwrite and fopen. Thanks
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Quote:
Originally Posted by michiganannd View Post
Hi; I'm a newbie. Im trying to do this code:
PHP Code:
                      <?php
$vidlink 
'http://www.yourdomain.com/';
$str=file_get_contents($vidlink);
$fulltype '.html';
$b "1";
$filename $b.$fulltype;
file_put_contents($b.$fulltype$str);    
chmod($filename0777);
$somecontent "\nSomething here\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

    if (!
$handle fopen($filename'r+')) {
         echo 
"Cannot open file ($filename)";
         exit;
    }

    
// Write $somecontent to our opened file.
    
if (fwrite($handle$somecontent) === FALSE) {
        echo 
"Cannot write to file ($filename)";
        exit;
    }

    echo 
"Success";

    
fclose($handle);

} else {
    echo 
"The file $filename is not writable";
}
?>

I want to add a content in the beginning of the page but it always cut down the


Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
and it appears as

Code:
    My new content TML 4.01 Transitional//EN"> 
thats why the page is broken...
Can you please help me so it doesnt cut down the first doctype of the page when i add a new content.

Thanks in advance

P/s: seems like it always overwrite the doctype line... if i try to write it at the bottom of the page then it is fine.
It's php code so you can remove this line...

Quote:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Just start your php code with:

<?php
and end with
?>

...And when it comes to your html code....

Start with <HTML> and end with </HTML>

That should sum this up
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 10-15-2008, 03:27 AM Re: Please help with fwrite and fopen. Thanks
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
$string = 'My stuff';
$string .= file_get_contents(...);
file_put_contents($file, $string);
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Please help with fwrite and fopen. Thanks
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22105 seconds with 12 queries