James Revillini

Say 'no' to styrofoam.

Month: January 2008

PHP Script: Convert Excel or tab-delimited file to html table

Here’s a script which I wrote today while on the jorb.  The purpose was so that someone could copy and paste from an excel spreadsheet into a textarea, click a button, and voila: an html table.

The nice thing was that when I pasted Excel data into the textarea, it was tab-delimited with line breaks.  At that point, all I needed to do was some replacements and throw a table wrapper on it.

Here’s the code for the conversion function (sorry – i haven’t installed a php code parser yet to style this more nicely):

<?php
/**
* convert tab delimited file to html table
* @input string tab-delimited text
* found at http://james.revillini.com
* note: you are not required to keep the above copyright notice in this code.
*/
function tabs_to_table($input) {
//define replacement constants
define(‘TAB_REPLACEMENT’, ‘</td><td> ‘);
define(‘NEWLINE_REPLACEMENT’, ‘</td></tr><tr%s><td> ‘);
define(‘TABLE_BEGIN’, ‘<table><tr><td> ‘);
define(‘TABLE_END’, ‘</td><tr></table>’);</code>

//replace all tabs with end-cell, begin-cell
$input = preg_replace  (’/\t/’  , TAB_REPLACEMENT  , $input);

//split the list on linebreaks
$rows = preg_split  (’/\r\n/’  , $input);

//replace all linebreaks with end-row, begin-row (with or without altRow class)
$output = ”;
foreach ($rows as $index => $row) {
$output .= $row . sprintf(NEWLINE_REPLACEMENT, ($index%2?”:’ class=”alt”‘));
}

//build table
$input = TABLE_BEGIN . $output . TABLE_END;
return ($input);
}
?>

Joomla Tip: “mgmedia2 component not installed. Please install first to use the plugin.”

If you are seeing “mgmedia2 component not installed. Please install first to use the plugin.” then you probably either

  1. just tried to uninstall the mgmedia2 thing from your Joomla admin panel, or
  2. are trying to install mgmedia2.

If you want to uninstal mgmedia2, make sure you go to Installers > Mambots and uninstall the mambot/plugin as well.

If you want to install mgmedia2, you missed a step and you still need to installed the component in Installers > Components. See readme.

I just wanted to put this out there in case anyone is struggling with it.

[SOLVED] Dreamweaver: Site-wide, design time style sheets using templates

Prerequisites:

  1. Every page of your site must be a PHP file, or some kind of server side language file.
  2. You must use Dreamweaver templates to make the design-time stylesheet automatically apply itself to the pages of your site.

This solution is not going to work for everyone because of the two prereqs above; sorry about that. But if you do meet those requirements, then your life just got a LOT easier.

It’s simple:

  1. Open your template.
  2. Switch to code view.
  3. Go to the <head> tag
  4. insert this code:
    <?php if (false) : //design time style sheet hack ?>
    <link href="../css/
    yui-2.4.1-dwcs3-design-time.css" rel="stylesheet" type="text/css">
    <!-- add as many DT stylesheets as you want in this area! -->
    <?php endif; ?>
  5. Save the template (and apply it to all the pages of your site).

Notes:

The linked stylesheet file is one I use to correct the rendering of a YUI Grids-based layout because natively, Dreamweaver renders it with the main .yui-b block taking only half of the space of the #bd element.

And a note to Adobe:

BUILD THIS FUCKING FEATURE INTO THE GODDAMNED SOFTWARE. (This is the first time I’ve ever sworn on the record on the Web. Sorry for offending non-Adobe employees.)

Dynamically populate an element styled with white-space: pre

Assume:

You cannot use:

You must do this:

Lame, huh?

Killing me softly: Searchindexer.exe

Do you have a process that won’t die? Tired of searchindexer.exe calling you at home to harrass you for the rent? Do you have credit card debt?

Your solution is here! OK, what you want to do to prevent searchindexer.exe (searchprotocolhost.exe) from spawning every time some MS product loads, just follow these simple steps:

  1. Start > Run
  2. Enter ‘services.msc’ and hit Enter.
  3. Find ‘Windows Search’
  4. Punch the screen (just kidding)
  5. Double-click (on the Win Search item)
  6. Set ‘Start-up type’ to ‘Manual’.
  7. Click the ‘Stop’ button if it is enabled (because that means the service is running)
  8. Click the ‘Log On’ tab
  9. Select each hardware profile item on the list, one at a time, and click ‘Disable’ for each one.

That should stop it from running without hacking your system to bits. Now, I have to say that I have NO IDEA what this is going to do to the searchability of your MS products. I mean, if Outlook is firing it up, it must be indexing your e-mail with it or something, so who knows what effects it could have ultimately. But in the mean time, enjoy the CPU time you’ll save, which I believe translates to energy savings as well. It must, right?

If I’m wrong, educate me.

© 2017 James Revillini

Theme by Anders NorenUp ↑