[thelist] PHP help with fopen (I think)

Tara Cleveland tara at taracleveland.com
Fri Mar 15 15:32:01 CST 2002


Hi all,

Here I am the non-programmer type sticking my finger into the programming
fire...

Okay, so I've got this page (call it "Home"). I want the Home page to open
another page (call it "text"). I want the Home page to take the first
sentence on the text page (not a whole HTML page just text), and put it into
the middle of the Home page.

Are you with me so far?? 'Cause I'm not sure I am...

So with very little knowledge of PHP I'm trying to do this and obviously
getting a bit muddled up.

I've figured out (and please correct me if I'm wrong) that if you do fopen,
the contents of the file (text) are treated as an array. But I've been
trying to implode and explode this array and getting totally confused about
what I'm supposed to be doing. The PHP book I've got is very unclear about
all this. Sometimes it sort of works, sometimes not.

Here's the page it's on:
<http://michaelkaufman.passport.ca/newsite/index.php>

The php bit is under the News and Events on the right hand side.
If you click the second read more link, you can see the other page that has
the full article on it. Right now it's not taking the first sentence, it's
taking the whole file.

Here's the PHP code I'm using (this seems to work on my own site, but not
here).

<?php
// This opens the newsandevents file and reads the first sentence and puts
it here

    $TheFile = "newsandevents/newsandevents.php";
    $Open = fopen ($TheFile, "r");

    if ($Open){
        $Data = file ($TheFile);

        for ($n = 0; $n < count($Data); $n++){
            $Sentence = explode(". ", $Data[$n]);
            print ("$Sentence[0].</p>");
        }
        fclose ($Open);
    }
    else {
    print ("Unable to read from text!<br>\n");
    }
?>

Thanks in advance to everyone. And Happy Friday! too.

Tara


--
Tara Cleveland
Web Design and Consulting
http://www.taracleveland.com




More information about the thelist mailing list