php Posts

Easy Markdown with Syntax Highlighting, PHP Edition

Easy Markdown with Syntax Highlighting, PHP Edition

Hi there, and welcome back to this 14th installment of "I rewrote my blog in another framework that I'm interested in learning, this time in Laravel". The trick that we'll be exploring today is that, in contrast to Python (the last version was in Django), PHP's lib story is a bit more sparse for this exact use case. However, I'm completely pleased with the outcome, so let's get busy!

PHP Markdown

Google that term and you'll find this -...

Reversing strings in PHP

Was asked this question recently, and haven't done any low level string manipulation w PHP in a little while. Couldn't remember the signature of substr(), but that wasn't my method anyway. Mine was more like iterating over an index, working from the back forward and concat-ing that on to a new string. Also, this is like 5 minutes worth of code, so cut me some slack.


echo "\nString reverse test\n\n";

function bench_it($func) {
  if (function_exists($func)) {
    $str =...

What is curl_setopt()?

When I first started getting into this, I read a lot on PHP and remember clearly having my eyes go crossed when I came across code like this --

// Example code: Creating Drupal 7 nodes by POSTing from cURL in PHP:

$site = "";
$user = "someusername";
$pass = "theusersassword";
$crl = curl_init();
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_USERAGENT, 'PHP script');
curl_setopt($crl, CURLOPT_COOKIEJAR, "/tmp/cookie.txt");

Database migrations with CodeIgniter - 101

So I've decided to start playing around with CodeIgniter. It's a supremely simple PHP framework that has a lot of good documentation, a pretty big user/developer base, and has a lot in common stylistically with Rails. I've just really started playing around with it, and wanted to use the migrations feature for building up my database. I won't explain what migrations are or how they work or why to use them because that's been covered.

Our project will be something like a database of...