Jump to content

trying to write to a web page


turtleman8605

Recommended Posts

I am trying to write a script for an interactive calendar. What I want to do is to click on a date, and have a box appear with a form to add an event to that date in the calendar. The box is a hidden div that becomes visible when a date is clicked (using javascript) and the form is doing what its supposed to do. Now what I am having trouble with is appending the calendar to show the new date. I was trying to use fopen and then str_replace but since the page is being viewed the file won't open.

Link to comment
Share on other sites

ok here's the code:

 

function process_form(){

echo ('<script type="text/javascript">initImage()</script>');

 

$file = 'calendar.php';

$currentString = '<td class="num"><a href="#" onClick="initImage()">18</a></td>';

$newString = '<td class="pop">26

  <p class="event">

    <a href="#"><b>'. $_POST['title'] .'</b>

    <span class="ev_pop">

  <span><strong>men in drag</strong> Event</span>

  <p>'. $_POST['event'] .'</p>

  <b>Date:</b> '. $_POST['date'] .'<br />

  <b>Time:</b> '. $_POST['time'] .'<br />

  <b>Place:</b> '. $_POST['place'] .'<br />

  <b>Admission:</b> '. $_POST['admis'] .'

    </span></a>

  </p>

</td>';

$lineAppend = str_replace( $currentString, $newString, $currentString );

$fh = fopen($file, 'a') or die("Cannot open file");

fwrite ( $fh, $lineAppend );

fclose ($fh);

 

And here's the problems:

1) when I execute it on the page, it doesn't up where the existing code is, but (as append mode does), tags it on the end of the page.

2) in order for it to work like this, I have to give public write permissions on my server.

 

Link to comment
Share on other sites

I don't understand, what you do here:

$lineAppend = str_replace( $currentString, $newString, $currentString );

You simply replace an existing string with another? wouldn't be

$lineAppend = $newString;

simpler?

Why do you write another file? I think It would be much simpler to write all in one file to generate the calendar...

Link to comment
Share on other sites

the reason I am using str_replace is because I am trying to get this section of code to appear in a certain date on the calendar represented by a cell in a table. also, I'm not using another file, it's all in one. I just need to figure out how to get the input text to show up where its supposed to go instead of at the end of the page.

Link to comment
Share on other sites

are you saying that you're trying to append something or write something in a file in the middle of the file?

 

consider using file_get_contents('fileurl');

to get the contents of the file instead of fopen

 

then use regex to replace or find a certain string, and replace it with something else, in a certain spot

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.