<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sean Behan&#039;s Web Development Portfolio and Blog &#187; php</title>
	<atom:link href="http://seanbehan.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com</link>
	<description>Web Development, Wordpress, Moodle, Ruby on Rails and Design in Burlington, Vermont</description>
	<lastBuildDate>Fri, 30 Jul 2010 17:17:12 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Check if the Current Logged In User can Edit a Course in MOODLE Using the Has_capability Function</title>
		<link>http://seanbehan.com/programming/how-to-check-if-the-current-logged-in-user-can-edit-a-course-in-moodle-using-the-has_capability-function/</link>
		<comments>http://seanbehan.com/programming/how-to-check-if-the-current-logged-in-user-can-edit-a-course-in-moodle-using-the-has_capability-function/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 02:36:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[moodle]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[context]]></category>
		<category><![CDATA[course]]></category>
		<category><![CDATA[has_capbility]]></category>
		<category><![CDATA[teacher]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1072</guid>
		<description><![CDATA[After an hour of fruitless searching through the docs and forums, I finally found an answer to my simple question, of course buried in the depths of the shark infested, murky water that is the Moodle code base .
How do I check if a user is a course creator for a given course? I&#8217;m still [...]


Related posts:<ol><li><a href='http://seanbehan.com/programming/review-of-moodle-1-9-extension-development/' rel='bookmark' title='Permanent Link: My Review of Moodle 1.9 Extension Development'>My Review of Moodle 1.9 Extension Development</a></li>
<li><a href='http://seanbehan.com/php/moodles-most-important-function-gets-no-attention/' rel='bookmark' title='Permanent Link: Moodle&#8217;s Most Important Function Gets No Attention'>Moodle&#8217;s Most Important Function Gets No Attention</a></li>
<li><a href='http://seanbehan.com/linux/add-user-directories-to-apache2-web-server/' rel='bookmark' title='Permanent Link: Add User Directories to Apache2 Web Server'>Add User Directories to Apache2 Web Server</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>After an hour of fruitless searching through the docs and forums, I finally found an answer to my simple question, of course buried in the depths of the shark infested, murky water that is the Moodle code base .</p>
<p>How do I check if a user is a course creator for a given course? I&#8217;m still not 100% sure, the access control policy seems needlessly confusing on first glance and even after reading the heady and mostly pointless, expose on how roles/perms are calculated (Available Here: http://docs.moodle.org/en/How_permissions_are_calculated ) If you notice the section titled &#8220;Some Practical Examples&#8221; is 100% empty! (I&#8217;ve added my code to the wiki so not 100% empty any longer) The most useful part of the docs are completely empty! Instead boatloads of time went into a treatise on the internals and lovely graphs like this one <img class="alignnone" src="http://docs.moodle.org/en/images_en/9/9c/Role_calc_table2.png" alt="" width="756" height="256" /></p>
<p>But you could always hop into the forum dedicated just to this chunk of the code base (Available here: http://moodle.org/mod/forum/view.php?f=941&amp;page=0) and search through the 500 topics w/ 5000+(i didn&#8217;t actually count) nested discussions (including version 1.7 of moodle as well).</p>
<p>No, instead, ACK came to the rescue and I found a snippet that performed the task.</p>
<p>Without further ado</p>
<pre>$context = get_context_instance(CONTEXT_COURSE, $course-&gt;id);
if (has_capability('moodle/course:update', $coursecontext)) {
  /** do stuff here */
}
</pre>
<p>There it is. That could have saved me an hour if mentioned in the docs!</p>


<p>Related posts:<ol><li><a href='http://seanbehan.com/programming/review-of-moodle-1-9-extension-development/' rel='bookmark' title='Permanent Link: My Review of Moodle 1.9 Extension Development'>My Review of Moodle 1.9 Extension Development</a></li>
<li><a href='http://seanbehan.com/php/moodles-most-important-function-gets-no-attention/' rel='bookmark' title='Permanent Link: Moodle&#8217;s Most Important Function Gets No Attention'>Moodle&#8217;s Most Important Function Gets No Attention</a></li>
<li><a href='http://seanbehan.com/linux/add-user-directories-to-apache2-web-server/' rel='bookmark' title='Permanent Link: Add User Directories to Apache2 Web Server'>Add User Directories to Apache2 Web Server</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/programming/how-to-check-if-the-current-logged-in-user-can-edit-a-course-in-moodle-using-the-has_capability-function/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Moodle&#8217;s Most Important Function Gets No Attention</title>
		<link>http://seanbehan.com/php/moodles-most-important-function-gets-no-attention/</link>
		<comments>http://seanbehan.com/php/moodles-most-important-function-gets-no-attention/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 23:36:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[moodle]]></category>
		<category><![CDATA[patterns]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1067</guid>
		<description><![CDATA[Arguably the most important function in the Moodle API, is the create_course function. One would think&#8230; after all Moodle is an LMS. Courses are the bread and butter for course management platforms, right? Taking a look at the function in the course/lib.php file reveals almost nothing about the function! WTF? &#8230; btw, the function starts [...]


Related posts:<ol><li><a href='http://seanbehan.com/programming/how-to-check-if-the-current-logged-in-user-can-edit-a-course-in-moodle-using-the-has_capability-function/' rel='bookmark' title='Permanent Link: How to Check if the Current Logged In User can Edit a Course in MOODLE Using the Has_capability Function'>How to Check if the Current Logged In User can Edit a Course in MOODLE Using the Has_capability Function</a></li>
<li><a href='http://seanbehan.com/programming/review-of-moodle-1-9-extension-development/' rel='bookmark' title='Permanent Link: My Review of Moodle 1.9 Extension Development'>My Review of Moodle 1.9 Extension Development</a></li>
<li><a href='http://seanbehan.com/linux/updating-your-twitter-status-with-curl-and-a-bash-function/' rel='bookmark' title='Permanent Link: Updating Your Twitter Status with cURL and a Bash Function'>Updating Your Twitter Status with cURL and a Bash Function</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Arguably the most important function in the Moodle API, is the create_course function. One would think&#8230; after all Moodle is an LMS. Courses are the bread and butter for course management platforms, right? Taking a look at the function in the course/lib.php file reveals almost nothing about the function! WTF? &#8230; <em>btw, the function starts at line 3260</em></p>
<pre>/**
 * Create a course and either return a $course object or false
 *
 * @param object $data  - all the data needed for an entry in the 'course' table
 */
function create_course($data) {
    global $CFG, $USER;
    /** omitted for your sanity */
}
</pre>
<p>Wow, I think I know less about this function now than before I went digging into the code. How do I assign a teacher to my new course, how do I populate the data object it takes as a parameter (is there a course setup function)? Since courses aren&#8217;t really objects in Moodle (just glorified arrays), am I just supposed to set them up by hand&#8230; $object-&gt;param = val?  Are there default values and/or required attributes that need to be set, otherwise my program is going to come to a halt? What about student enrollments? No example to help for how one might actually use this function? Do I have to really read through the code, starting at around line 3260, then jump between the rest of  this monstrous 4000 line piece of spaghetti coded file and try and make sense of it works (somehow).</p>
<p>How is it possible that the most important function (since the core problem Moodle solves is creating courses) in the entire application has no meaningful documentation? I think I have an answer. The entire code base is soooo convoluted and a giant waste of CPU cycles, that it would too embarrassing to actually document how it even works.</p>


<p>Related posts:<ol><li><a href='http://seanbehan.com/programming/how-to-check-if-the-current-logged-in-user-can-edit-a-course-in-moodle-using-the-has_capability-function/' rel='bookmark' title='Permanent Link: How to Check if the Current Logged In User can Edit a Course in MOODLE Using the Has_capability Function'>How to Check if the Current Logged In User can Edit a Course in MOODLE Using the Has_capability Function</a></li>
<li><a href='http://seanbehan.com/programming/review-of-moodle-1-9-extension-development/' rel='bookmark' title='Permanent Link: My Review of Moodle 1.9 Extension Development'>My Review of Moodle 1.9 Extension Development</a></li>
<li><a href='http://seanbehan.com/linux/updating-your-twitter-status-with-curl-and-a-bash-function/' rel='bookmark' title='Permanent Link: Updating Your Twitter Status with cURL and a Bash Function'>Updating Your Twitter Status with cURL and a Bash Function</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/php/moodles-most-important-function-gets-no-attention/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert Array to Object in PHP</title>
		<link>http://seanbehan.com/programming/convert-array-to-object-in-php/</link>
		<comments>http://seanbehan.com/programming/convert-array-to-object-in-php/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 17:58:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1060</guid>
		<description><![CDATA[
function array2obj($data) {
    return is_array($data) ? (object) array_map(__FUNCTION__,$data) : $data;
}

Source: http://www.serversidemagazine.com/php/how-to-convert-array-notation-to-object-notation


Related posts:Moodle&#8217;s Most Important Function Gets No Attention



Related posts:<ol><li><a href='http://seanbehan.com/php/moodles-most-important-function-gets-no-attention/' rel='bookmark' title='Permanent Link: Moodle&#8217;s Most Important Function Gets No Attention'>Moodle&#8217;s Most Important Function Gets No Attention</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<pre>
function array2obj($data) {
    return is_array($data) ? (object) array_map(__FUNCTION__,$data) : $data;
}
</pre>
<p>Source: <a href="http://www.serversidemagazine.com/php/how-to-convert-array-notation-to-object-notation">http://www.serversidemagazine.com/php/how-to-convert-array-notation-to-object-notation</a></p>


<p>Related posts:<ol><li><a href='http://seanbehan.com/php/moodles-most-important-function-gets-no-attention/' rel='bookmark' title='Permanent Link: Moodle&#8217;s Most Important Function Gets No Attention'>Moodle&#8217;s Most Important Function Gets No Attention</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/programming/convert-array-to-object-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the PHP Mail Function with Additional Headers</title>
		<link>http://seanbehan.com/php/using-the-php-mail-function-with-additional-headers/</link>
		<comments>http://seanbehan.com/php/using-the-php-mail-function-with-additional-headers/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 19:12:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[headers]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=791</guid>
		<description><![CDATA[Pass a fourth parameter to the mail() function with the header information.

&#60;?php
$to = "jane@example.com";
$subject = "Hello World!";
$body = "This will be sent from email-addr@example.com";
$headers = "From: email-addr@example.com\r\nX-Mailer: php";
mail($to, $subject, $body, $headers);



Related posts:Send Mail in Ruby with a Pony
Using sendmail to send mail on ubuntu box
Updating Your Twitter Status with cURL and a Bash Function



Related posts:<ol><li><a href='http://seanbehan.com/programming/send-mail-in-ruby-with-a-pony/' rel='bookmark' title='Permanent Link: Send Mail in Ruby with a Pony'>Send Mail in Ruby with a Pony</a></li>
<li><a href='http://seanbehan.com/linux/using-sendmail-to-send-mail-on-ubuntu-box/' rel='bookmark' title='Permanent Link: Using sendmail to send mail on ubuntu box'>Using sendmail to send mail on ubuntu box</a></li>
<li><a href='http://seanbehan.com/linux/updating-your-twitter-status-with-curl-and-a-bash-function/' rel='bookmark' title='Permanent Link: Updating Your Twitter Status with cURL and a Bash Function'>Updating Your Twitter Status with cURL and a Bash Function</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Pass a fourth parameter to the mail() function with the header information.</p>
<pre>
&lt;?php
$to = "jane@example.com";
$subject = "Hello World!";
$body = "This will be sent from email-addr@example.com";
$headers = "From: email-addr@example.com\r\nX-Mailer: php";
mail($to, $subject, $body, $headers);
</pre>


<p>Related posts:<ol><li><a href='http://seanbehan.com/programming/send-mail-in-ruby-with-a-pony/' rel='bookmark' title='Permanent Link: Send Mail in Ruby with a Pony'>Send Mail in Ruby with a Pony</a></li>
<li><a href='http://seanbehan.com/linux/using-sendmail-to-send-mail-on-ubuntu-box/' rel='bookmark' title='Permanent Link: Using sendmail to send mail on ubuntu box'>Using sendmail to send mail on ubuntu box</a></li>
<li><a href='http://seanbehan.com/linux/updating-your-twitter-status-with-curl-and-a-bash-function/' rel='bookmark' title='Permanent Link: Updating Your Twitter Status with cURL and a Bash Function'>Updating Your Twitter Status with cURL and a Bash Function</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/php/using-the-php-mail-function-with-additional-headers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generate MySQL Datetime Type Using PHP Date() Function</title>
		<link>http://seanbehan.com/php/generate-mysql-datetime-type-using-php-date-function/</link>
		<comments>http://seanbehan.com/php/generate-mysql-datetime-type-using-php-date-function/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 18:22:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[strftime]]></category>
		<category><![CDATA[type]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=779</guid>
		<description><![CDATA[If you want to insert a datetime that matches the default mysql datetime type format use this 

date('Y-m-d H:i:s');



Related posts:Managing Timestamps in MySQL with a Trigger
Problem slash Bug in Rails with attr_accessor and Datetime Select Fields
Custom Date Formats for Your Rails Application



Related posts:<ol><li><a href='http://seanbehan.com/databases/managing-timestamps-in-mysql-with-a-trigger/' rel='bookmark' title='Permanent Link: Managing Timestamps in MySQL with a Trigger'>Managing Timestamps in MySQL with a Trigger</a></li>
<li><a href='http://seanbehan.com/ruby-on-rails/problem-slash-bug-in-rails-with-attr_accessor-and-datetime-select-fields/' rel='bookmark' title='Permanent Link: Problem slash Bug in Rails with attr_accessor and Datetime Select Fields'>Problem slash Bug in Rails with attr_accessor and Datetime Select Fields</a></li>
<li><a href='http://seanbehan.com/ruby-on-rails/custom-date-formats-for-your-rails-application/' rel='bookmark' title='Permanent Link: Custom Date Formats for Your Rails Application'>Custom Date Formats for Your Rails Application</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>If you want to insert a datetime that matches the default mysql datetime type format use this </p>
<pre>
date('Y-m-d H:i:s');
</pre>


<p>Related posts:<ol><li><a href='http://seanbehan.com/databases/managing-timestamps-in-mysql-with-a-trigger/' rel='bookmark' title='Permanent Link: Managing Timestamps in MySQL with a Trigger'>Managing Timestamps in MySQL with a Trigger</a></li>
<li><a href='http://seanbehan.com/ruby-on-rails/problem-slash-bug-in-rails-with-attr_accessor-and-datetime-select-fields/' rel='bookmark' title='Permanent Link: Problem slash Bug in Rails with attr_accessor and Datetime Select Fields'>Problem slash Bug in Rails with attr_accessor and Datetime Select Fields</a></li>
<li><a href='http://seanbehan.com/ruby-on-rails/custom-date-formats-for-your-rails-application/' rel='bookmark' title='Permanent Link: Custom Date Formats for Your Rails Application'>Custom Date Formats for Your Rails Application</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/php/generate-mysql-datetime-type-using-php-date-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Paypal IPN Script</title>
		<link>http://seanbehan.com/php/php-paypal-ipn-script/</link>
		<comments>http://seanbehan.com/php/php-paypal-ipn-script/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 21:45:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[fsockopen]]></category>
		<category><![CDATA[ipn]]></category>
		<category><![CDATA[paypal]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=776</guid>
		<description><![CDATA[Simple script for posting a valid response back to Paypal service after a sale is completed using the Paypal Instant Checkout payment method. 

&#60;?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
  $value = urlencode(stripslashes($value));
  $req .= "&#038;$key=$value";
}

// post back to PayPal system to [...]


Related posts:<ol><li><a href='http://seanbehan.com/business/paypal-ipn-simulator/' rel='bookmark' title='Permanent Link: paypal ipn simulator'>paypal ipn simulator</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Simple script for posting a valid response back to Paypal service after a sale is completed using the Paypal Instant Checkout payment method. </p>
<pre>
&lt;?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
  $value = urlencode(stripslashes($value));
  $req .= "&#038;$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name        = $_POST['item_name'];
$item_number      = $_POST['item_number'];
$payment_status   = $_POST['payment_status'];
$payment_amount   = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id           = $_POST['txn_id'];
$receiver_email   = $_POST['receiver_email'];
$payer_email      = $_POST['payer_email'];

if (!$fp) {
// HTTP ERROR
} else {
  fputs ($fp, $header . $req);
  while (!feof($fp)) {
    $res = fgets ($fp, 1024);
    if (strcmp ($res, "VERIFIED") == 0) {
      // check the payment_status is Completed
      // check that txn_id has not been previously processed
      // check that receiver_email is your Primary PayPal email
      // check that payment_amount/payment_currency are correct
      // process payment
    } else if (strcmp ($res, "INVALID") == 0) {
      // log for manual investigation
    }
  }
fclose ($fp);
}
</pre>
<p>I grabbed this script from Paypal Docs&#8230; I never can find the info I need w/in their site so I&#8217;m posting here for reference.  <a href="https://www.paypal.com/us/cgi-bin/webscr?cmd=p/pdn/ipn-codesamples-pop-outside#php">https://www.paypal.com/us/cgi-bin/webscr?cmd=p/pdn/ipn-codesamples-pop-outside#php</a></p>


<p>Related posts:<ol><li><a href='http://seanbehan.com/business/paypal-ipn-simulator/' rel='bookmark' title='Permanent Link: paypal ipn simulator'>paypal ipn simulator</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/php/php-paypal-ipn-script/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Listing Files and Directories with PHP</title>
		<link>http://seanbehan.com/php/listing-files-and-directories-with-php/</link>
		<comments>http://seanbehan.com/php/listing-files-and-directories-with-php/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 18:27:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[directories]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[ksort]]></category>
		<category><![CDATA[read]]></category>
		<category><![CDATA[stat]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=774</guid>
		<description><![CDATA[Listing all files and directories using PHP 5.

&#60;?php
$files = array(); $dir = dir(".");
while(false!==($file=$dir-&#62;read())):
  if(($file{0}!=".") &#038;&#038; ($file{0}!="~") &#038;&#038; (substr($file, -3)!="LCK")
    &#038;&#038; ($file!=basename($_SERVER["PHP_SELF"]))):
      $files[$file] = stat($file); //
    endif;
endwhile;
$dir-&#62;close(); ksort($files); ?&#62;

&#60;table border=1 cellpadding=5&#62;
&#60;tr&#62;&#60;th&#62;Name&#60;/th&#62;&#60;th&#62;Size&#60;/th&#62;&#60;th&#62;Date&#60;/th&#62;&#60;/tr&#62;
&#60;?php foreach($files as $name =&#62; $stats): ?&#62;
  &#60;tr&#62;
    &#60;td&#62;&#60;?php print [...]


Related posts:<ol><li><a href='http://seanbehan.com/ruby/reading-writing-removing-files-and-directories-in-ruby/' rel='bookmark' title='Permanent Link: Reading, Writing, Removing Files and Directories in Ruby'>Reading, Writing, Removing Files and Directories in Ruby</a></li>
<li><a href='http://seanbehan.com/linux/add-user-directories-to-apache2-web-server/' rel='bookmark' title='Permanent Link: Add User Directories to Apache2 Web Server'>Add User Directories to Apache2 Web Server</a></li>
<li><a href='http://seanbehan.com/programming/recursively-zip-up-a-directory-while-excluding-certain-files/' rel='bookmark' title='Permanent Link: Recursively Zip Up a Directory while Excluding Certain Files Based on File Extension Type'>Recursively Zip Up a Directory while Excluding Certain Files Based on File Extension Type</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Listing all files and directories using PHP 5.</p>
<pre>
&lt;?php
$files = array(); $dir = dir(".");
while(false!==($file=$dir-&gt;read())):
  if(($file{0}!=".") &#038;&#038; ($file{0}!="~") &#038;&#038; (substr($file, -3)!="LCK")
    &#038;&#038; ($file!=basename($_SERVER["PHP_SELF"]))):
      $files[$file] = stat($file); //
    endif;
endwhile;
$dir-&gt;close(); ksort($files); ?&gt;

&lt;table border=1 cellpadding=5&gt;
&lt;tr&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Size&lt;/th&gt;&lt;th&gt;Date&lt;/th&gt;&lt;/tr&gt;
&lt;?php foreach($files as $name =&gt; $stats): ?&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;?php print $name;?&gt;&lt;/td&gt;
    &lt;td&gt;&lt;?php print $stats['size']; ?&gt;&lt;/td&gt;
    &lt;td&gt;&lt;?php print date("m-d-Y h:ia", $stats['mtime']); ?&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;?php endforeach; ?&gt;&lt;/table&gt;
</pre>


<p>Related posts:<ol><li><a href='http://seanbehan.com/ruby/reading-writing-removing-files-and-directories-in-ruby/' rel='bookmark' title='Permanent Link: Reading, Writing, Removing Files and Directories in Ruby'>Reading, Writing, Removing Files and Directories in Ruby</a></li>
<li><a href='http://seanbehan.com/linux/add-user-directories-to-apache2-web-server/' rel='bookmark' title='Permanent Link: Add User Directories to Apache2 Web Server'>Add User Directories to Apache2 Web Server</a></li>
<li><a href='http://seanbehan.com/programming/recursively-zip-up-a-directory-while-excluding-certain-files/' rel='bookmark' title='Permanent Link: Recursively Zip Up a Directory while Excluding Certain Files Based on File Extension Type'>Recursively Zip Up a Directory while Excluding Certain Files Based on File Extension Type</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/php/listing-files-and-directories-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Highlight String in PHP</title>
		<link>http://seanbehan.com/php/highlight-string-in-php/</link>
		<comments>http://seanbehan.com/php/highlight-string-in-php/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 16:57:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[file_get_contents]]></category>
		<category><![CDATA[highlight]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=765</guid>
		<description><![CDATA[Function for highlighting text/strings in PHP. 

$content = file_get_contents("http://php.net/");

print highlight("PHP", $content);

function highlight($match, $string){
  return str_ireplace($match, "&#60;span style='background:yellow'&#62;$match&#60;/span&#62;", $string);
}

Will output something like this 
***Notice all the styles are gone   &#8230; would need to parse the document body to maintain stylesheet and other &#8216;php&#8217; strings that might be in resources paths. 


Related posts:Absolutize Relative [...]


Related posts:<ol><li><a href='http://seanbehan.com/php/absolutize-relative-links-using-php-and-preg_replace_callback/' rel='bookmark' title='Permanent Link: Absolutize Relative Links Using PHP and Preg_Replace_Callback'>Absolutize Relative Links Using PHP and Preg_Replace_Callback</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Function for highlighting text/strings in PHP. </p>
<pre>
$content = file_get_contents("http://php.net/");

print highlight("PHP", $content);

function highlight($match, $string){
  return str_ireplace($match, "&lt;span style='background:yellow'&gt;$match&lt;/span&gt;", $string);
}
</pre>
<p>Will output something like this<br />
<div class="wp-caption alignnone" style="width: 355px"><img alt="Highlighted PHP.Net" src="http://farm5.static.flickr.com/4003/4297402799_22d2a0e816_o.jpg" title="PHP Highlight" width="345" height="334" style="background:#eeeeee;padding:3px;border:solid 1px #CCC;"/><p class="wp-caption-text">Highlighted PHP.Net</p></div></p>
<p>***Notice all the styles are gone <img src='http://seanbehan.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  &#8230; would need to parse the document body to maintain stylesheet and other &#8216;php&#8217; strings that might be in resources paths. </p>


<p>Related posts:<ol><li><a href='http://seanbehan.com/php/absolutize-relative-links-using-php-and-preg_replace_callback/' rel='bookmark' title='Permanent Link: Absolutize Relative Links Using PHP and Preg_Replace_Callback'>Absolutize Relative Links Using PHP and Preg_Replace_Callback</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/php/highlight-string-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Absolutize Relative Links Using PHP and Preg_Replace_Callback</title>
		<link>http://seanbehan.com/php/absolutize-relative-links-using-php-and-preg_replace_callback/</link>
		<comments>http://seanbehan.com/php/absolutize-relative-links-using-php-and-preg_replace_callback/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 17:29:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[absolute links]]></category>
		<category><![CDATA[file_get_contents]]></category>
		<category><![CDATA[preg_replace_callback]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[relative links]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=727</guid>
		<description><![CDATA[I was in the market for a simple php script to replace hrefs with their absolute paths from scraped web pages. I  wrote one myself. I used the preg_replace_callback function so that I could pass the parsed results as a single variable. 

&#60;?php
$domain = "http://seanbehan.com";
$pattern = "/\bhref=[\"&#124;'](.*?)[\"&#124;']/";
$string = file_get_contents($domain);

// prepends relative links w/ $domain [...]


Related posts:<ol><li><a href='http://seanbehan.com/programming/parse-for-links-with-prototype-js/' rel='bookmark' title='Permanent Link: Parse for Links with Prototype JS'>Parse for Links with Prototype JS</a></li>
<li><a href='http://seanbehan.com/programming/how-to-importexport-your-wordpress-blogroll-er-your-links/' rel='bookmark' title='Permanent Link: How to Import/Export Your Wordpress Blogroll&#8230; er, Your Links'>How to Import/Export Your Wordpress Blogroll&#8230; er, Your Links</a></li>
<li><a href='http://seanbehan.com/programming/offset-an-element-with-relative-position-property-without-taking-up-any-space-in-document/' rel='bookmark' title='Permanent Link: Offset an Element with Relative Position Property with CSS Without Taking Up Any Space in the Document'>Offset an Element with Relative Position Property with CSS Without Taking Up Any Space in the Document</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I was in the market for a simple php script to replace hrefs with their absolute paths from scraped web pages. I  wrote one myself. I used the preg_replace_callback function so that I could pass the parsed results as a single variable. </p>
<pre>
&lt;?php
$domain = "http://seanbehan.com";
$pattern = "/\bhref=[\"|'](.*?)[\"|']/";
$string = file_get_contents($domain);

// prepends relative links w/ $domain skips returns the match if already absolute
function replace_href($match){
  global $domain;
  if(substr($match[1], 0, 7)!=="http://" &#038;&#038; substr($match[1],0,8)!=="https://"){
    return "href='".$domain.$match[1]."'";
  } else {
    return "href='".$match[1]."'s";
  }
}
print preg_replace_callback($pattern, "replace_href", $string);
</pre>


<p>Related posts:<ol><li><a href='http://seanbehan.com/programming/parse-for-links-with-prototype-js/' rel='bookmark' title='Permanent Link: Parse for Links with Prototype JS'>Parse for Links with Prototype JS</a></li>
<li><a href='http://seanbehan.com/programming/how-to-importexport-your-wordpress-blogroll-er-your-links/' rel='bookmark' title='Permanent Link: How to Import/Export Your Wordpress Blogroll&#8230; er, Your Links'>How to Import/Export Your Wordpress Blogroll&#8230; er, Your Links</a></li>
<li><a href='http://seanbehan.com/programming/offset-an-element-with-relative-position-property-without-taking-up-any-space-in-document/' rel='bookmark' title='Permanent Link: Offset an Element with Relative Position Property with CSS Without Taking Up Any Space in the Document'>Offset an Element with Relative Position Property with CSS Without Taking Up Any Space in the Document</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/php/absolutize-relative-links-using-php-and-preg_replace_callback/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Grab a Twitter Status without the Twitter API</title>
		<link>http://seanbehan.com/php/grab-a-twitter-status-without-the-twitter-api/</link>
		<comments>http://seanbehan.com/php/grab-a-twitter-status-without-the-twitter-api/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 01:53:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=703</guid>
		<description><![CDATA[Quick and dirty way to grab the users status messages without having to go through the twitter api (not having to authenticate that is). You can grab the RSS feed and indicate the number of statuses returned with the count param. I wrote this function for my blog  in PHP. It uses the curl [...]


Related posts:<ol><li><a href='http://seanbehan.com/linux/updating-your-twitter-status-with-curl-and-a-bash-function/' rel='bookmark' title='Permanent Link: Updating Your Twitter Status with cURL and a Bash Function'>Updating Your Twitter Status with cURL and a Bash Function</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Quick and dirty way to grab the users status messages without having to go through the twitter api (not having to authenticate that is). You can grab the RSS feed and indicate the number of statuses returned with the count param. I wrote this function for my blog  in PHP. It uses the curl extension so if it&#8217;s not installed type </p>
<pre>
apt-get install php5-curl
</pre>
<p>Otherwise you&#8217;ll have to use the fsockopen function. Then it&#8217;s just a matter of parsing the XML and getting at what data you want. I just want one status so I&#8217;m accessing the element directly, rather than looping over the returned data set. </p>
<pre>
&lt;php
function latest_twitter_status_message(){
        // grab the rss feed link from some user, like me and indicate the count in the url
	$host = "http://twitter.com/statuses/user_timeline/11036982.rss?count=1";
	// using curl
	$ch = curl_init($host);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	$data = curl_exec($ch);
	curl_close($ch);
	$doc = new SimpleXmlElement($data, LIBXML_NOCDATA);
	return "{$doc->channel->item[0]->description}";
}
</pre>


<p>Related posts:<ol><li><a href='http://seanbehan.com/linux/updating-your-twitter-status-with-curl-and-a-bash-function/' rel='bookmark' title='Permanent Link: Updating Your Twitter Status with cURL and a Bash Function'>Updating Your Twitter Status with cURL and a Bash Function</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/php/grab-a-twitter-status-without-the-twitter-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
