PHP

  • warning: Creating default object from empty value in /home1/nate01/public_html/modules/taxonomy/taxonomy.pages.inc on line 33.
  • strict warning: Non-static method view::load() should not be called statically in /home1/nate01/public_html/sites/all/modules/views/views.module on line 1113.
  • strict warning: Declaration of views_handler_field::query() should be compatible with views_handler::query($group_by = false) in /home1/nate01/public_html/sites/all/modules/views/handlers/views_handler_field.inc on line 1147.
  • strict warning: Declaration of views_handler_argument::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home1/nate01/public_html/sites/all/modules/views/handlers/views_handler_argument.inc on line 917.
  • strict warning: Declaration of views_handler_argument::query() should be compatible with views_handler::query($group_by = false) in /home1/nate01/public_html/sites/all/modules/views/handlers/views_handler_argument.inc on line 917.
  • strict warning: Declaration of views_handler_sort::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home1/nate01/public_html/sites/all/modules/views/handlers/views_handler_sort.inc on line 165.
  • strict warning: Declaration of views_handler_sort::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /home1/nate01/public_html/sites/all/modules/views/handlers/views_handler_sort.inc on line 165.
  • strict warning: Declaration of views_handler_sort::query() should be compatible with views_handler::query($group_by = false) in /home1/nate01/public_html/sites/all/modules/views/handlers/views_handler_sort.inc on line 165.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home1/nate01/public_html/sites/all/modules/views/handlers/views_handler_filter.inc on line 587.
  • strict warning: Declaration of views_handler_filter::query() should be compatible with views_handler::query($group_by = false) in /home1/nate01/public_html/sites/all/modules/views/handlers/views_handler_filter.inc on line 587.
  • strict warning: Declaration of views_plugin_query::options_submit() should be compatible with views_plugin::options_submit($form, &$form_state) in /home1/nate01/public_html/sites/all/modules/views/plugins/views_plugin_query.inc on line 169.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home1/nate01/public_html/sites/all/modules/views/plugins/views_plugin_row.inc on line 136.
  • strict warning: Non-static method view::load() should not be called statically in /home1/nate01/public_html/sites/all/modules/views/views.module on line 1113.
  • strict warning: Declaration of views_plugin_pager_none::post_execute() should be compatible with views_plugin_pager::post_execute(&$result) in /home1/nate01/public_html/sites/all/modules/views/plugins/views_plugin_pager_none.inc on line 69.

Trim Text to a Certain Length on a Word Boundary in PHP

$caption = $your_starting_text;
 
if (strlen( $caption ) > 230) {  
     print preg_replace('/\s+?(\S+)?$/', '', substr( $caption , 0, 230)) . '...';
} else {
     print $caption ; 
}

Firebug Extension for AJAX Development

FirePHP enables you to log to your Firebug Console using a simple PHP method call. All data is sent via response headers and will not interfere with the content on your page.

FirePHP is ideally suited for AJAX development where clean JSON and XML responses are required.

http://www.firephp.org

Post to Facebook Wall/Timeline with the Facebook PHP SDK

<?php
 
 require_once '../facebook/facebook_sdk/src/facebook.php';
 
// configuration
 $appid = [APP ID];
 $appsecret = [SECRET APP KEY];
 $msg = 'Some message would go here.';
 $title = 'Some title would go here';
 $uri = 'http://nathanbolin.com';
 $desc = 'Some detailed message that shows beneath the title.

HTTP POST to a REST Service through PHP

Representational state transfer (REST) is a style of software architecture for distributed systems such as the World Wide Web. The term representational state transfer was introduced and defined in 2000 by Roy Fielding in his doctoral dissertation.

Configure LAMP Server for Drupal 7 and Migrate Development Site - No GUI, command line only

To start with, I created a tarball with bz2 compression of the dev site. Make sure to explicitly include .htaccess because the tar command, like the ls command does not include filenames with "." as the first character. Navigate to the root of your site and execute the following (-c create | -v verbose (lists files as it goes) | -j bz2 compression | -f file):

tar -cvjf nameofsite_date_of_copy.tar.bz2 * .htaccess

Also, you will need the mysqldump

PHP Get Current URL

Sometimes it is not as straightforward as one may think to get the current url to use it inside your application. Here is a snippet that I use to fetch the current URL and use it in a script. The current url (whether http or https) is now a local variable that you can do with as you please.

$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] :
 
"http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

You should groom this value before using in anything sensitive, like a sql query.

Mobile Device Detection in PHP

<?php
 
function mobile_device_detect($iphone=true,$ipad=true,$android=true,$opera=true,$blackberry=true,
$palm=true,$windows=true,$mobileredirect=false,$desktopredirect=false){
 
  $mobile_browser   = false; 
// set mobile browser as false till we can prove otherwise
 
  $user_agent       = $_SERVER['HTTP_USER_AGENT']; 
// get the user agent value - this should be cleaned to ensure no nefarious input gets executed
 
  $accept           = $_SERVER['HTTP_ACCEPT']; 
// get the content accept value - this should be cleaned to ensure no nefarious input gets executed
 
  switch(tr

Read a CSV in PHP line by line and access each field

<?PHP
 
$file_handle = fopen("widgets.csv", "r");
 
while (!feof($file_handle) ) {
 
$line_of_text = fgetcsv($file_handle, 1024);
 
print $line_of_text[0] . $line_of_text[1]. $line_of_text[2] . "<BR>";
 
}
 
fclose($file_handle);
 
?>

Of course, you would increase the index of $line_of_text[i] if you had more than 3 columns.

Syndicate content