Tech Support > Computers & Technology > Graphics & Designing > PHP question (fread, fwrite, fme, fyou)
PHP question (fread, fwrite, fme, fyou)
Posted by erika on February 11th, 2004


I know a few of you on here are fairly well versed developers. Here is a
question..cry for help..whatever..

Here is what I am trying to do.
--------------------------------------
Read a PHP or TXT document into the TEXTAREA of a different page.


Here is what I have going on.
--------------------------------------------------

I have a password protected page, with a form element that allows me to post to
a text document. It works..Weeee...
(i'm sure you can see where I am going with this )
I need to be able to extract the information from the txt file into the
textarea so everytime I access the page..I can change the content. Currently,
Nothing appears in the TEXTAREA..It's blank whenever I access the page.
However, I am able to ADD text using the TEXT AREA..

Essentially..I'm trying to write a little news logger using only a news page
(txt file), and an updater page.

If anyone can point me in the right direction ( sans "use a database") it would
be greatly appreciated. I have spent countless hours screwing myself into the
ground over the past few days..Trying to poke through 10 million tutorials and
websites that are much more involved than I really need. Or I am too stupid to
wrap my head around them...Thanks in advance.

-brian

PS- I am posting under my gf;s screenname.

Posted by LauraK on February 11th, 2004


You might want to take a look at SnippetMaster. It may do what you want.
http://www.snippetmaster.com/index.html
CuteNews may be a possible. It uses a flatfile database instead of mysql.
http://cutephp.com/
And another one:
http://bensscripts.andkon.com/site.php?id=2


laurak@madmousergraphics.com
http://www.madmousergraphics.com
web design, print design, photography



Posted by Rastin Mehr on February 11th, 2004


Are you using php version 4.3 or higher? you can just use this function:

$myString = file_get_contents("mytextfile.txt", "r");

This function returns the content of your *.txt file as a string. If the
file doesn't exist, or it is empty, the function will return "false"

Here is more information about this function:
http://ca.php.net/manual/en/function...t-contents.php

If your PHP version is not 4.3 or higher the following should do the job.


function file_get_contents($filename, $use_include_path = 0)
{
$file = @fopen($filename, "rb", $use_include_path);
if ($file)
{
while (!feof($file)) $data .= fread($file, 1024);
fclose($file);
}
return $data;
}


Rastin

erika wrote:

--
Rastin Mehr
---------------------------------------------------
rmd Studio
http://www.rmdStudio.com
http://www.netphotography.com (New site)
---------------------------------------------------
"Great spirits, have always encountered violent
opposition from mediocre minds" Albert Einstein

Posted by Rastin Mehr on February 11th, 2004


Oh if you need to update and manage multiple news instances, you may
want to use a database driven system for sure. Flat file wouldn't be as
efficient. Search under content management system CMS php scripts or
applications, I'm sure I've seen free ones out there. Unfortunately I
can't help much in this case. I usually code it myself.

Rastin


--
Rastin Mehr
---------------------------------------------------
rmd Studio
http://www.rmdStudio.com
http://www.netphotography.com (New site)
---------------------------------------------------
"Great spirits, have always encountered violent
opposition from mediocre minds" Albert Einstein

Posted by Matt Bostock on February 11th, 2004


Hey Bri,

How's it going?

What code are you using to print the textfile inside the textarea? It should
look like this:

<textarea craphere="morecraphere"><?php print(htmlentities($textfileData,
ENT_QUOTES)); ?></textarea>

HTH,
Matt
--
Banging your head against a wall uses 150 calories an hour.


"erika" <procksucks@aol.com11111111> wrote in message
news:20040211013021.28324.00001806@mb-m15.aol.com...

---
No viruses found in this message.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.581 / Virus Database: 368 - Release Date: 9/2/04



Posted by IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII on February 11th, 2004


Laura, Matt and Rastin..

Laura..Thanks for the links..I'll check them out..

Matt and Rastin..No dice..I'm totally stumped..I emailed this guy who runs a
PHP tutorial website..He hasn't been able to figure it out as of 5:00pm this
afternoon..
Looks like both the snippets of code you guys sent are almost exactly what this
guy sent me...Maybe I will upload and post a link to this crap..

My brain is full...
But before it explodes..This is what I would like to learn how to do using
PHP..

1. Finish this flat file news logger thing.

2. Learn how to build a navigation that corresponds to pages..For instance, If
you click on NEWS..The news page would load..and the graphic of the NEWS PAGE
in the navigation would remain in it's rolled over state. I saw some tutorial
on this on ALISTAPART..But it was strictly for CSS..Helpful..But I would like
to learn how to do this using images..

3. In conjunction with 1 and 2..I would like to learn how to assemble all of
the above in a dynamic site..I've been pissing around with functions..Loading
different pages into different sections of a page..That kind of crap..But I'm
not sure I'm doing it in the most efficient way. AND..Even if I am..I'm still
not sure how to approach the navigation includes ( See #2 ).

Any suggestions?? Good simple tutorials you can point me to? ( ones that sound
as if a normal human being wrote them..Not R2D2...)..I came to the conclusion a
long time ago that my brain doesn't work in programming terms. I'm not a very
logical person...I'm a space cadet..So I need stuff that is REALLY dummied
down..

-brian
KILLED BY DESIGN
http://www.killedbydesign.com

NEW AND IMPROVED WEB HOSTING
http://www.mindfieldmedia.com

Posted by SpaceGirl on February 11th, 2004



"IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII" <iiii666iiii@aol.comIIIIIIII> wrote in
message news:20040211181158.12638.00002091@mb-m29.aol.com...
This is not possible, that's why. It breaches the DOM. You cannot target
anything from server-side script because that means the server needs to know
other pages and windows are open in the browser. This breaches the DOM
security model. So, work around. Client side script. Have the data sent to a
hidden layer containing a hidden iframe, which contains a page. Because this
is a child object of the current page, you can then have your server write a
string of javascript which will be executed there and then.... well
something along these lines.

Also, build your page out of templates and includes. Look at the main page
on www.subhuman.net - there are 5 distict modules that run on the server to
generate different elements of the page before any of it is sent to the
client. Sometimes the modules will even write javascript directly to the
page depending on your web browser. This means I can target ANYTHING on the
page, regardless of the DOM and regardless of local security.

Okay that's a complicated way of saying it, but I can explain more if you
want. I can show you how to do everything you've mentioned really simply in
ASP, but I dont know ANY PHP.



Posted by Matt Bostock on February 11th, 2004


Mirri I'm half-asleep so this mightn't make much sense, but which part isn't
possible? Nothing he said seemed impossible as far as I can tell right
now..?

Cheers,
Matt
--
Banging your head against a wall uses 150 calories an hour.


"SpaceGirl" <NoSpaceSpamGirl@subhuman.net> wrote in message
news:c0ee47$169ccc$1@ID-129131.news.uni-berlin.de...

---
No viruses found in this message.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.581 / Virus Database: 368 - Release Date: 9/2/04



Posted by Matt Bostock on February 11th, 2004


Here ya go bud...
http://www.adultnetsurprise.com/lear...hp_week_1.html

It's a tutorial site for learning PHP for adult webmasters :-D I learnt all
the basics from that Also don't be afraid to go to php.net and use their
search feature to look for functions, cos frankly it's bloody brilliant.

Send me the script if you like, we'll get ya up n running.

That's no problem. You'd use some if..then statements to decide which image
state to display. You can detect which page you are currently on by using
this:
basename($_SERVER['PHP_SELF']);

So you'd have something like this...

<img src="myNewsImage<?php

$thisPage = basename($_SERVER['PHP_SELF']);

if($thisPage == "news.php"){
print("On");
} else {
print("Off);
}

?>.gif" alt="crap" etc etc />

Thinking about it... if your making each section of the site on a different
page, you could just change it manually on each page without PHP. If you're
going for the 'index.php?action=news' route, you'd use something like the
above, only '$thisPage' would equal "$prefixhere_action". If you're not sure
where the hell the 'prefixhere' part comes from, ask me and I'll explain.
Orrrr... if you're using a page for the nav, and then simply including it in
all the other pages, like a shared template, then use my code above...
simple

See above

Peace,
Matt
--
Banging your head against a wall uses 150 calories an hour.


"IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII" <iiii666iiii@aol.comIIIIIIII> wrote in
message news:20040211181158.12638.00002091@mb-m29.aol.com...

---
No viruses found in this message.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.581 / Virus Database: 368 - Release Date: 9/2/04



Posted by IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII on February 12th, 2004


Not sure what to say here..Because I know nothing about "the DOM"..But some
dude gave me a snippet of code to make it kind of work..
It's a document with a form field..That calls a TXT document into it for
reading and writing...So whenever i open the page. The text document I am
editing loads in the textfield. However. I cannot figure out how to make it
editable in the sense that whenever I delete text..It deletes it..It just adds
one string onto the next string of text. Maybe deleting strings is a breach of
the DOM? I dunno?
-brian
KILLED BY DESIGN
http://www.killedbydesign.com

NEW AND IMPROVED WEB HOSTING
http://www.mindfieldmedia.com