Jump to content

[SOLVED] Positioning where to write


graham23s

Recommended Posts

Hi Guys,

 

i was wondering if it was possible to position where the:

 

fwrite($file, "<b>Time:</b> $time<br />");

 

writes to, i have started a table and wanted the fwrite to write new <td> afte this:

 

<table width="100%" border="1" bordercolor="#000000" cellpadding="0" cellspacing="0" />
<tr>
<th align="center">Date</th><th align="center">IP</th><th align="center">Came From</th>
</tr>

 

so fwrite would write a new entry over and over keeping in line with the table, is this possible at all?

 

thanks guys

 

Graham

Link to comment
Share on other sites

try this too:

 

TEXT FILE NAMED html_parse_4_links.txt:

what the heck
<div id='somediv'>im ready for a big glass of coke</div>
blah blah blah

 

PHP FILE NAMED html_parse_4_links.php:

<html>
<head>
<style type="text/css">
#editbox { width:500px; height:200px; }
</style>
</head>
<body>
<?php
if ($_GET['editbox'] != ""){ //if the editbox has anything in it
$filename = 'html_parse_4_links.txt'; //this is the file to write to
$edit = $_GET['editbox']; //this is the contents of the editbox
$before = $_GET['before'];
$after = $_GET['after'];
$somecontent = urldecode($before);
$somecontent.= "<div id='somediv'>";
$somecontent.= $edit;
$somecontent.= "</div>";
$somecontent.= urldecode($after);
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
    // In the example, they were opening $filename in append mode "a", but here we are overwriting the file in mode "w".
	//"a" mode might be pretty cool for a appending a blog with a user comment...
    if (!$handle = fopen($filename, 'w')) {
         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, wrote ($somecontent) to file ($filename)";
    fclose($handle);
} else {
    echo "The file $filename is not writable";
}
}else{
	$url = "html_parse_4_links.txt";
	$input = @file_get_contents($url) or die('Could not access file: $url');
	$regexp = "(.*)<div id='somediv'>(.*)<\/div>(.*)";
	if(preg_match_all("/$regexp/si", $input, $matches)) {
		$beforeEdit = urlencode($matches[1][0]);
		$string = $matches[2][0];
		$theEdit = htmlentities($string);
		$afterEdit = urlencode($matches[3][0]);
		echo "<form action='html_parse_4_links.php' method='get'>
					<input type='text' name='editbox' id='editbox' value='$theEdit'></input>
					<input type='hidden' name='before' value='$beforeEdit'></input>
					<input type='hidden' name='after' value='$afterEdit'></input>
					<input type='submit' value='Save Back 2 File' />
				</form>";
	}
}
?>
</body>
</html>

 

All you would have to do is modify the code slightly.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.