views:

71

answers:

2

I think my method is lame, but I cannot think of a better way to do this.

I use Ultraedit text editor to hold all the stuff I cull out of Stackoverflow for PHP and MySQL in a text file. This is my strict format for each new entry:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
TITLE: THIS IS MY TITLE (ALL IN CAPS, FOLLOWD BY A DOTTED LINE)
-------------------------------------------------
...probably a question first (if necessary), then another shorter dotted line
-------------------
...answer(s)...
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

So, here is an actual entry:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
TITLE: READING FIRST 5 FIELDS OF CSV FILE INTO PHP
-------------------------------------------------
(...with fgetcsv...)
        $row = 1;
        if (($handle = fopen("test.csv", "r")) !== FALSE) {
            while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                $num = count($data);
                echo "<p> $num fields in line $row: <br /></p>\n";
                // iterate over each column here
                for ($c=0; $c < $num; $c++) {
                    // handle column data here
                    echo $data[$c] . "<br />\n";
                    // exit the loop after 3rd column parsed
                    if ($c == 2) break;
                }
                ++$row;
            }
            fclose($handle);
-----------------
(...without fgetcsv...)
        $lines = file('data.csv');
        $linecount = count($lines);
        for ($i = 1; $i < $linecount; $i++){
           $fields = explode(',', $lines[$i]);
           $sno  = $fields[0];
           $name = $fields[1];
           $ph   = $fields[2];
           $add  = $fields[3];
        }http://stackoverflow.com/users/login?returnurl=%2fquestions%2fask
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

I can get a list of titles by searching for "TITLE: *", etc. My text file now contains about 15,000 lines. Is there a better way to do this? I have asked StackOverflow before about snippet software, but after a thorough search, there is really nothing out there that fits my needs.

In a way, I'm surprised that there is not a PHP/MySQL application for doing this (collecting snippets). I can't do it because I don't have the knowledge or talent. The snippet collector in my IDE will not suffice.

Thanks!

+2  A: 

why not build yourself a little application with a small sql backend (say SQLCE or SQLITE)?

You could build it so that you have the following tables:

  • Title
  • Code Snippet
  • Original Question Url

and then you can relate in the TAGS of the question via another Table to allow better searching/cross referencing.

Stephen Wrighton
As a "learner," I can try but I'm quite sure I'd screw it up.
dave
But "screwing" up things like that is how you learn. It's also a good way to practice things like designing a programming, building test cases and db design and optimization.
Stephen Wrighton
A: 

I have used InfoSelect software for years for this purpose, and have many megabytes of searchable notes and code snippets. It isn't exclusively for code snippets. It's the software equivalent of keeping notes on index cards and being able to arrange them in hierarchies, or do a search on them.

Another similar tool is OneNote which is part of Microsoft Office.

If you remove the condition that your tool should be specifically for tracking code snippets, you may be able to broaden your choices.

DOK
Thanks. I didn't know InfolSelect was still available. Has it not be upgraded since 2007? OneNote has some issue with 64bit OS...forget exactly what the problem is...?
dave