Tag Archive for python

3: PHP

After learning about SQL and regular expressions I was still limited to working within a text editor and query browser.  For the most part that was okay – as long as anyone I wanted to share information was sitting with me at my desk.

As business manager I had to keep selling at all times.  To the sales department, key clients, R&D and my bosses.

An internal marketing department had recently formed and they graciously provided us space to build product-specific web pages.  They didn’t have the resources to help us build or maintain sites so for the most part they were used as FAQ pages.

I had already been bitten by the programming bug and wanted to extend my reach from query browser to web browser.

It’s hard to avoid the fact that PHP is the most common language used to move data from server to browser.  It also goes hand-in-hand with MySQL.  I was ahead of the curve in the sense that I already knew what to Google.

By no means am I an expert PHP programmer.  The first tasks I learned to perform with it were:

  • Connect to a database
  • Query the database
  • Loop through the results
  • Insert lines into an HTML table

A couple of years ago I was intrigued by Google’s Natural Language Toolkit (NLTK).  Since it was written as a Python add-in I figured Python was the only language suitable for parsing text into data.  I was excited to be at the point where I might at least understand a bit of the pattern matching magic our R&D department was performing.  I liked Python because it had it’s own console (IDLE) which made it easy to noodle around with.  The whole hashbang (#!) thing seemed cool and edgy but I suspected I wasn’t using it properly.  I really didn’t need NLTK anyway.  It would be interesting to use it for sentiment analysis but for me identifying regular expressions was good enough.

I wrote a script that loaded a plain text 13F filing from the SECs website and parsed it.  company name, address, date, security and holdings were all easy enough to extract with regex and I thought I needed Python for that.

The easiest way for me to pass data from Python to PHP was for Python to create xml tags and write the results to a document and then have PHP read the document.  There had to be a better way.

I wasn’t giving php enough credit.  It turns out that I could do the whole thing in PHP.  Extracting the data, formatting it as xml, loading the xml into MySQL and querying it back as an array could all be done in one .php file.  Once the results are written into HTML table cells you have yourself a table.  But the table just sits there.  You can’t sort, filter or analyze it.

This site you’re reading now is WordPress, which uses PHP and MySQL extensively.

Code Samples

Snippets of php, python, javascript and SQL