PHP fopen write to single line

<?php
$text = "Here is my new line.";
$newline = "$text\n"
$filename = $_SERVER['DOCUMENT_ROOT'] . "/myfile.php";
if (!($fp = fopen($filename, 'a'))) {
  print 'Cannot open file';
} else {
  if(fwrite($fp, "$newline")){
    print "line written<br />\n";
  } else {
    print "problem writing line\n";
  }
  if(fclose($fp)){
    print 'file closed';
  } else {
    print 'problem closing file';
  }
}
?>

MySQL backup and restore

#backup
DATEVAR=`date +%Y-%m-%d--%H-%M-%S`;
mysqldump -u[username] -p[password] [database_name] > backup_$DATEVAR.sql;
 
#restore
mysql -u[username] -p[password] [database_name] < backup_$DATEVAR.sql;
 
## In one command, dump the remote into local ##
ssh -C username@mysite.com mysqldump -u[remote user] -p[remote pass] [remote db] | mysql -u[local user] -p[local pass] [local db]

Drupal path alias from nid

<?php
// get the alias for any node:
$path = drupal_get_path_alias("node/".$nid);
// or get the alias for current page
$path = drupal_get_path_alias();
 
// get the full path
$full_path = $GLOBALS['base_url'] . $GLOBALS['base_path'] . $path;
?>

Drupal 6 poll theming

Theming polls is not that hard when you know what to do:

First, you can use templates to theme everything except the radios:

  • poll-vote.tpl.php
  • poll-vote-block.tpl.php (must also copy over poll-vote.tpl.php)
  • poll-results.tpl.php