p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

beginning_php thread: RE: Setting null and empty spaces in searches

Message #1 by "Lawrence" <spam@k...> on Fri, 4 Oct 2002 15:40:03 -0400
This function works well up to the fwrite. The echo statement works when it is not commented. It's not

You can view the form on the web here:


I'm writing this script as a macro to help out a friend. She is interested in harvesting info from this page:


Specifically, the link that says

Division Staff

I've been plugging in those two, and clicking "add domain to address" button. It all works except the fwrite.

I took on the project because it sounded like an interesting challenge. Makes the web a little bit more like a
database. And, anyway, she is a good friend. She's been gathering this info by hand, and its a real pain. She just
needs every line in each page that has "instruc" or "curric" in it. I'll get to that part later. For now, I just
need to get the thing to write to disk. Permissions are 755, which should be fine, I think? Modes "w+" and "a+"
both have the same trouble, I think. Any ideas? (Once again, I'm not using some really neat new PHP functions
because the server is running something like PHP 4.01.)

function makePageOfUrlArray($fileOpenMode="a+") {
 global $targetPage, $visibleLinkText, $relativeFromRoot;
 $urlArray = getUrlArray($targetPage, $visibleLinkText, $relativeFromRoot);
 $fileString = "";
 for ($i=0; $i < count($urlArray); $i++) {
  // Get a web page into an array and turn it into a string. Echo it and then
  // get the next string. In the end we're going to make a big file of it.
  $eachTargetPage = $urlArray[$i];
  $fcontents = file($eachTargetPage) or die("Couldn't open the $i page.");
  for ($r=0; $r < count($fcontents); $r++) {
      $fileString .= $fcontents[$r];
  $fileString = strip_tags($fileString);
  $fileString = nl2br($fileString);
  $fileString .= "<BR><BR><BR>#X#X#X<BR><BR><BR>";

 //echo $fileString;

 global $PHP_SELF;
 $self = $PHP_SELF;
 $fp = fopen("collateWebPagesProject.htm", "r") or die("Wasn't able to open the file on the web host.");
 fwrite ($fp, $fileString) or die("Had trouble writing all the information to disk.");
 echo "The file, which is a collation of possibly many web pages, <a href='collateWebPagesProject.htm'>has been
created and can be viewed here</a>. <br><br>You can also <a href='$self'>go back to the main page to begin
with this document.</a>";

  Return to Index