PHP Find in Context Primer Tutorial

PHP Find in Context Primer Tutorial

PHP Find in Context Primer Tutorial

We’ve discussed PHP as a great server-side language that we use at our rjmprogramming.com.au domain and the three modes of use that PHP works, when we presented PHP Desktop Command Line Follow Up Tutorial as shown below. You may recall those PHP modes of use as …

  • “surfing the net” calling the PHP from a web browser’s address bar
  • curl” call of the PHP
  • “command line” execution of PHP

… and today, with our “Find in Context” usage we are not suggesting using it on our live rjmprogramming.com.au domain at this stage in any meaningful way except as a downloadable PHP file representation, because what we are constructing here is like a desktop app for command line “Find in Context” use.

Let me take you through an example (that you can see a lot about studying today’s tutorial picture) of how the “Find in Context” PHP web application can be used …

  1. You start the “Find in Context” with a “surfing the net” URL mode of use of the PHP (but not on rjmprogramming.com.au) and would prefer its use using a localhost URL via the use of a local web server that hosts PHP, such as the great MAMP local web server (which would ask that URL, in all likelihood to be HTTP://localhost:8888/find_in_context.php … which brings up the …
  2. HTML form asks for and/or displays …
    • Linux command prefix (readonly): fgrep -wnHC9
    • Search RegEx string
    • Filespec on local web server’s disk
    • One to Nine record after (any match) contextual RegEx match fields
    • One to Nine record before (any match) contextual RegEx match fields
  3. Clicking the “Process…” button kicks off a PHP exec invocation of a PHP “command line” mode of use (of the same codebase of) find_in_context.php (where “command line) ($argc $argv[]) arguments are passed rather than $_GET[] arguments … which …
  4. Executes the fgrep (with that contextually useful -C9 switch helping out) to an “internal use only” file … which …
  5. On completion of the PHP “command line” mode of use execution that same file is reread for “One to Nine record” checking purposes to weed out unnecessary report data and …
  6. Present findings to the user at the “surfing the net” invocation as a report appended by another HTML form for another “Find in Context” should the user require this

Perhaps you can see here how a local web server like MAMP is that link between …

  • the HTTP: or HTTPS: protocol required by the web server file processing capabilities of PHP (and best means of displaying a useful user interactive tool like an HTML form element)… and …
  • the local web server underlying operating system’s (“fgrep” command access of its) file system disk (as if we were using a desktop application “Browse…” button scenario) accessed via PHP exec call of a PHP “command line” invocation (on the understanding that a MAMP install is best followed by a fixing of PATH conditions so that the command line command “PHP” points to MAMP’s PHP software “engine”)


Previous relevant PHP Desktop Command Line Follow Up Tutorial is shown below.

PHP Desktop Command Line Follow Up Tutorial

PHP Desktop Command Line Follow Up Tutorial

Yesterday we started on some PHP desktop tutorials for a XML Chapter Changes via the Substitution of Strings desktop job when we presented PHP Desktop Command Line Primer Tutorial as shown below.

Of the three web modes of use today’s improvement work is …

  • web browsing (or “surfing the net”) … we add an HTML form as pictured … that one is relatively easy
  • command line usage … we leave it as is, interactively asking the user for information … though you could approach this with a menu system perhaps
  • curl on the command line … now this is more problematic because of the difficulty with interactive input and curl usage … so we …
    1. in the first instance expect the user to type
      “curl //www.rjmprogramming.com.au/PHP/renumber_more.php”
      at the command line to start off
    2. the user sees on the command line the output of the underlying HTML as if web browsing, but it contains a more complex
      “curl //www.rjmprogramming.com.au/PHP/renumber_more.php?curlget=%7Cfilespec%3DCOM_.IOVBK%2F%2A.xml%7Cynftt%3D%23%40%21%40%23%7Cprefix1%3Dolink%3E%7Cprefix2%3Dolink+targetptr%3D%22start%22%3E%7Cprefix3%3Dolink+targetptr%3D%22end%22%3E%7Cprefix4%3Dlabel%3D%22%5B%7Cprefix5%3Dlabel%3D%22%7Cprefix6%3DCOMM.IOVBK%7ECH.%7Clookup%3D%5B30.%2C%5B29.%7C%5B32.%2C%5B30.%7C%5B33.%2C%5B31.%7C%5B34.%2C%5B32.%7C%5B35.%2C%5B33.%7C%5B36.%2C%5B34.%7C%5B37.%2C%5B35.%7C%5B38.%2C%5B36.%7C%5B39.%2C%5B37.%7C%5B40.%2C%5B38.%7C%5B41.%2C%5B39.%7C%5B42.%2C%5B40.%7C%5B43.%2C%5B41.%7C%5B46.%2C%5B42.%7C%5B47.%2C%5B43.%7C%5B48.%2C%5B44.%7C%5B49.%2C%5B45.%7C%5B50.%2C%5B46.%7C%5B50A.%2C%5B47.%7C%5B52.%2C%5B48.%7C%5B53.%2C%5B49.%7C%5B54.%2C%5B50.%7C%5B55.%2C%5B51.%7C%5B56.%2C%5B52.%7C%5B59.%2C%5B53.%7C%5B60.%2C%5B54.%7C%5B61.%2C%5B55.”
      type of suggestion command line idea which the user can copy and adjust (in that encoded way, unfortunately, using vertical bar | as the major delimiter) into another copy buffer
    3. the user pastes that adjusted new complex curl command onto the command line, to complete the task

All in all, we do not recommend curl usage, for this job!

Here is that PHP code …


Previous relevant PHP Desktop Command Line Primer Tutorial is shown below.

PHP Desktop Command Line Primer Tutorial

PHP Desktop Command Line Primer Tutorial

Sometimes you have desktop program requirements involving files and the operating system. If the job is quite large you’d probably want to involve one of the well known IDEs like Xcode for Mac or Visual Studio for Windows or perhaps NetBeans or Code:Block and they could provide solutions in a whole gamut of compilable programming languages such as C++, C#, VB.Net, C or Java, just to name a few.

To avoid some of this bother for smaller jobs we recommend, in Windows, Digital Mars C (or D), and we’ve talked about that here.

Today we start on a short journey to show you that PHP at the command line, with command line curl, or as a web application (especially with a local MAMP web server on Mac or EasyPHP web server on Windows) can be another option. Do you remember PHP Modes of Use File Traverse Tutorial?

The job we show today is an XML Chapter Changes via the Substitution of Strings desktop job. In this job we have …

  1. a filespec, on the desktop (or USB) of input data files
  2. a mapping string file (or the data of) to map the chapter information, only, that is of interest

… from that we start with a quick MAMP web application solution … we’ll show you here as renumber_more.php_GETME full of hardcodings and assumptions.

We rid the code of many hardcodings to genericize it considerably, and we show you some of that journey via renumber_more.php-GETME where we introduced some PHP command line interactive usage where we got help from this link (thanks). This interactivity only happens in the PHP usage from the command line, and to test for that we …


if (isset($argv[0])) { // PHP command line specific interactive input code below ...
//
// PHP command line specific interactive input code
//
} // ... end of PHP command line specific interactive input code

Here is that PHP code …

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Operating System, Tutorials and tagged , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>