Jump to content

Make a callable function out of this codes?


ztealmax

Recommended Posts

hi i have 2 pieces of code these 2:

First->

<?php

$path = "news"; // path to the dir you want to scan

foreach(glob("$path/*", GLOB_ONLYDIR) as $catdir) {
// catogories start
$catogories = ("".$catdir.".description");
$catfile = fopen($catogories, 'r') /*or die('Could not open file!')*/;
$catdata = fread($catfile, filesize($catogories)) /*or die('Could not read file!')*/;
fclose($catfile); 
$catdir = ereg_replace("news/", "", "$catdir");
echo "<a href='".$_SERVER['PHP_SELF']."?content=news'><b>".$catdir."</b></a>  ".$catdata."<br>";

}

?>

SECOND

<?php
  function in_dir ($file, $in_dir)
  {
      $dir    = realpath ($file);
      $in_dir = realpath ($in_dir);

      if (!is_dir ($file)) {
          $dir = dirname ($file);
      }

      do {
          if ($dir === $in_dir) {
              $is_in_dir = TRUE;
              break;
          }
      } while ($dir !== ($dir = dirname ($dir)));

      return (bool) @$is_in_dir;
  }
  $dir = $path;
echo $dir;
  $dh  = opendir($dir);
  while (false !== ($filename = readdir($dh))) 
{
   $pattern = '/\.news$/';
   if(preg_match($pattern,$filename))
   {
      /*    You can proceed because the file has the extension .zip       */
   $filename = ereg_replace($dir, "", "$filename");
  $filename = ereg_replace(".news", "", "$filename");
echo "<a href='?content=read&contents=".$dir."".$filename.".news'>" . $filename . "</a><br>";
   }
}

?>

 

 

this bit from first code

echo "<a href='".$_SERVER['PHP_SELF']."?content=news'><b>".$catdir."</b></a>  ".$catdata."<br>";

would be nice to make it an clickable function instead so i incorporate SECOND piece of code in to the first, but im not sure how to make a php function

 

What i need it to do is

 

first code scans folder and show all dirs as clickable links (complete and it works)

second piece of code scan subfolder and makes clickable links so function call should be something like:

 

echo "<a href=' CALL THE FUNCTION '><b>".$catdir."</b></a>  ".$catdata."<br>";

 

DOes this make any sence?

 

//Cheers

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.