Jump to content

Search the Community

Showing results for tags 'grep'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 2 results

  1. Hello - hoping to find some direction with this. I think this is fairly simple for more experienced php coders but I'm having trouble with it. It's a php grep text string search that results in a list of files that contain the string. Hoping to split the $results value (list of file names) into separate links to open the file. I was able to convert into a link for the first file listed, but it links to that same file for all the entries in the list. I assume that maybe an array of $results needs to be created first rather than try and work with $results at the end? <?php /** * E.Yekta * cafewebmaster.com */ define("SLASH", stristr($_SERVER[SERVER_SOFTWARE], "win") ? "\\" : "/"); $path = ($_POST[path]) ? $_POST[path] : dirname(__FILE__) ; $q = $_POST[q]; function php_grep($q, $path){ $fp = opendir($path); while($f = readdir($fp)){ if( preg_match("#^\.+$#", $f) ) continue; // ignore symbolic links $file_full_path = $path.SLASH.$f; if(is_dir($file_full_path)) { $ret .= php_grep($q, $file_full_path); } else if( stristr(file_get_contents($file_full_path), $q) ) { $ret .= "$file_full_path\n"; } } return $ret; } if($q){ $results = php_grep($q, $path); } echo <<<HRD <pre > <form method=post> <input name=path size=100 value="$path" /> Path <input name=q size=100 value="$q" /> Query <input type=submit> </form> $results </pre > HRD; ?> php_grep.php
  2. Can't seem to find a solution to this: I want to use the following readdir code: ++++++++++++ <?php if ($handle = opendir('.')) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != ".." && $entry != "sort.php" && $entry != "sort2.php" && $entry != "index.php") { echo "<a href='$entry'>$entry</a><br />"; } } closedir($handle); } ?> ++++++++++++ The above code works perfectly to display all the files in my directory. (All the files to be displayed on my webpage are .pdf files (the code above excludes the .php files in the directory).) These pdf files consist of multiple Catalog_date.pdf, Schedule_date.pdf and Newsletter_date.pdf files, each of which category I want to place in a separate column. To do this, I have three CSS column class <div> sections. I will put the above code in each of the three <div class> sections and exclude two of the three categories depending on which column it is. I was using another code to do this that works perfectly in all respects. It lists the separate categories in separate columns. (see image file below): ++++++++++++ <?php $string = 'Catalog'; echo ""; $PATH = $_ENV['DOCUMENT_WWW']; $d=$PATH.'.'; $files=array(); $dir = opendir($d) or die("couldn't open directory"); while ($f = readdir($dir)) { if (!eregi("\.jpg",$f) && $f!=='.' && $f!=='..' && eregi("$string",$f) && eregi("\.pdf",$f)){ #if does not match .jpg . and .. array_push($files,"$f"); echo "<a href='$f'>$f</a><br>"; } if( is_dir($_dir)) closedir( $d );} ?> ++++++++++++ But "eregi" has been deprecated and I wanted to update my php code to account for this. However, I don't know how to simulate the "f (!eregi("\.jpg",$f) && $f!=='.' && $f!=='..' && eregi("$string",$f) && eregi("\.pdf",$f))" part that allows me to fill the Catalog column with only the Catalog_date.pdf files, etc. (I have attached my currently working page that uses the older code as the example of what I want to do.) Can anyone help me with either including only those files that begin with the word Calendar_, Schedule_ or Newsletter_ for each script; or excluding two of the three files that begin with those words? I have looked at the info in the PHP Manual as well as other Googled places, but don't find enough information to make the code function. Hope this makes sense. Any assistance greatly appreciated. Shelley
×
×
  • 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.