GetDotted Domains

Viewing Thread:
"PHP Help"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Fri 16/05/03 at 16:03
Regular
Posts: 787
I'm fiddling about with my site at the moment and I want to be able to get a few little things working using PHP.

All I want is a basic script that allows information that is submitted through a text box to appear on the site.

When I say basic I mean basic as in monkey_man's old chat scripts he used to have on his site.

Anybody know of any basic tutorials that could explain how to do this?

I've got a feint idea of what to do, just not how to do it!

Thanks.
Sat 31/05/03 at 23:53
Regular
"Eff, you see, kay?"
Posts: 14,156
strip_tags() will get rid of those
s.
Sat 31/05/03 at 22:27
Regular
"Chavez, just hush.."
Posts: 11,080
hahaha

All I had to do was to write the thingy and it worked fine...

It's funny. It really is.

*laughs to self*
Fri 30/05/03 at 20:21
Regular
"Chavez, just hush.."
Posts: 11,080
Becuase I know nothing, I'm confusing you!

Say I was to insert this:

Test

Test

Test

Test

Into a text box and write it to a text file using this code:

if ($Data) {
$Data = stripslashes($Data);
$File = "file.txt";
if (file_exists($File)) {
$fp = fopen($File, "w");
flock($fp, 2); # Lock the File.
fputs($fp, "$Data\n");
flock($fp, 3); # Release the File Lock.
fclose($fp);
[CUT]

I can then call it up on a page using this code:

$File = "mainframe.txt";
if (file_exists($File)) {
$fp = fopen($File, "r");
flock($fp, 1); # Lock the File.

while (! feof($fp)) {
$Line = fgets($fp, 1024);
print "$Line
\n";
}

flock($fp, 3); # Release the File Lock.
fclose($fp);
} else {
print "

Can't include the text, file doesn't exist or
can't be opened.

\n";
}
?>

And it displays it how I submitted it in the text box.

Say I wanted to call the contents of the text up within a text box so I could edit it, if I used that code above it would display the text like this.

Test





Test





Test





Test





How would I edit that code I used to call up the text so that it deletes all the
bits? If they're there they end up making bigger and bigger gaps each time the data is submitted.
Wed 28/05/03 at 21:57
Regular
"It goes so quickly"
Posts: 4,083
ok, so what you are after is something which will remove the
from the data while it is in your textarea box, but put back when you submit it, so the
's are still in place in the file???

Why not have something like this:

$newstring = str_replace("
", "\n", $string);

... before writing the data to the textarea, then this after it:

$newstring = str_replace("\n", "
", $string);
Wed 28/05/03 at 20:07
Regular
"Chavez, just hush.."
Posts: 11,080
It's me not knowing anything.

There isn't a $string in there.

I just saw the thing posted today and thought that it may have some relevance to the subject!

I've got to include the $string in there somewhere haven't I?

I just don't have a clue...

-------------------

See, I don't actually know what I'm nattering on about. I just saw it and thought, 'hmmmmmmm.'
Wed 28/05/03 at 19:37
Regular
"It goes so quickly"
Posts: 4,083
Oh, and where you have:

$newstring=str_replace("
", "",$string);

Where does the data for $string come from? Seems empty to me
Wed 28/05/03 at 19:36
Regular
"It goes so quickly"
Posts: 4,083
Very quickly as I'm about to eat ... I read over that fast so may have got it wrong.

Why not have a seperate variable with the same data, but which has the
removed, so you display it with the
but write it back without?

Like I said, off to eat, so will read it correctly later :)
Wed 28/05/03 at 19:11
Regular
"Chavez, just hush.."
Posts: 11,080
OK, time for a new problem.

I'm probably doing this the wrong way in the first place but I don't care!

I'm using the code:

$File = "mainframe.txt";
if (file_exists($File)) {
$fp = fopen($File, "r");
flock($fp, 1); # Lock the File.
$newstring=str_replace("
", "",$string);
while (! feof($fp)) {
$Line = fgets($fp, 1024);
print "$Line
\n";
}

flock($fp, 3); # Release the File Lock.
fclose($fp);
} else {
print "

Can't include the text, file doesn't exist or can't be opened.

\n";
}
?>

To open up a text file from within a form box so that I can edit something and then submit it again as it's edited form.

Thing is, because of all the
bits in there, unless I delete them by hand they just keep leaving bigger and bigger gaps between sentances.

How would I go by getting rid of the
bits so that they will not appear when I open the file? When the text is resubmitted the new
bits will automatically be created by the code.

(This is where I'm gonna make stuff up which won't make any sense!)

I'm gonna guess that it's got something to do with this from MMs thread.

$newstring=str_replace(" ", "",$string);

Which can be edited to something like this:

$newstring=str_replace("
", "",$string);

How would I go by inserting that into the original code so it kills the
bits?

ELSE

Tell me the correct way to do it and not the way that I've just made up.

:c)

Thanks.
Mon 26/05/03 at 22:46
Regular
"Chavez, just hush.."
Posts: 11,080
Yeah, it's the long way to do it but it works and it will look better if the results are all in one line.

Just seen what it would look like with loads of blank lines because of wrapped data and it looks poo.

So much better when each line is a new date and the information goes sideways. it may be a bit of hassle but it's the best way (and easiest for me!)

Hmmmm, just thought about maybe changing the font size....
Sun 25/05/03 at 19:31
Regular
"It goes so quickly"
Posts: 4,083
So, you are using a seperate file for each row of information??

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Many thanks!
You were 100% right - great support!
I've been with Freeola for 14 years...
I've been with Freeola for 14 years now, and in that time you have proven time and time again to be a top-ranking internet service provider and unbeatable hosting service. Thank you.
Anthony

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre
Feedback Close Feedback

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.