Open .xls HTML content with Open Office

Author: admin / Category: Programming Secrets

Open .xls HTML content with Open Office

It looks like there’s a little bug in Open Office… If you have an .xls file with HTML content, if you open it with Microsoft Excel, it will look like an Excel table, but if you try to open it with Open Office, the HTML content will be displayed instead of the table.

Here’s how you can make it to work:

- instead of trying opening the file by double clicking it from Explorer, open a new, clean Open Office Calc spreadsheet, and open the file by selecting from the menu: File->Open.

Here is a small code to test it:

<html><body><table border=1>
<tr><th>a<th>b<th>c</tr>
<tr><td>1<td>2<td>3</tr>
<tr><td>4<td>5<td>6</tr>
<tr><td>7<td>8<td>9</tr>
</table></body></html>

New Yahoo! Messenger virus

Author: admin / Category: Programming Secrets

Yahoo! Messenger virusThis post is for all of my dear friends…

Starting with today, I saw that some of my friends got a new Yahoo! Messenger virus, sending every 10 minutes a message to the users from the application’s list.

The links look like:

http://ariafotos.com/image.php

http://zhelefun.com/image.php

http://tviceimg.com/image.php

After a little ‘Googleing’ here is the solution to fix your computer…

1st solution, for computer experts:

Delete the following files:

%Windir%\infocard.exe (acesta va fi si procesul activ)
%Windir%\mds.sys
%Windir%\mdt.sys
%Windir%\winbrd.jpg

Delete the following registry keys:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\ [Firewall Administrating = "%Windir%\infocard.exe"]
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Windows\CurrentVersion\Run\ [Firewall Administrating = "%Windir%\infocard.exe"]
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\ [Firewall Administrating = "%Windir%\infocard.exe"]

2nd solution for every-day users:

Download Malwarebytes Anti-Malware from HERE.

Install and make sure to check the Update Malwarebytes’ Anti-Malware and Launch Malwarebytes’ Anti-Malware.

After launching the program, select Perform full scan, and hit the Scan button. Wait for the program to execute the verification.

When finished, press Show Results. Make sure to select every item from the list, then press Remove Selected. Your computer will ask for a restart. After, you’re done. :)

Post twitter tweets from php with tinyurl links

Author: admin / Category: Programming Secrets

My boss just asked me to look for a script, capable of adding content to a twitter page from a site’s database. Very important, the twitter post needs to contain links to the website posts. And because they need to be as short as possible, i used the tinyurl API to dynamically create the short version of the urls. Here is a very simple code how to post to twitter some content:

require(‘twitterAPI.php’);

$twitter_username =’YourTwitterUsername’;
$twitter_psw =’YourTwitterPassword’;

$url = ‘YourLink’;
$tweet = ‘YourTweet’;
$url = TinyURL($url);
$twitter_status=postToTwitter($twitter_username, $twitter_psw, $tweet.’ : ‘.$url);

function TinyURL($u){
return file_get_contents(‘http://tinyurl.com/api-create.php?url=’.$u);
}

You can download the TwitterApi from twitterAPI.php

Check all uncheck all HTML checkboxes with Javascript

Author: admin / Category: Programming Secrets

The following little piece of code shows how to check all / uncheck all HTML checkboxes with simple Javascript, without jQuery. It’s not something hard to do, but as I use it a lot, it’s nice to have it at one click…

<form name=”formname” method=”POST” action=”?action=dosomething”>
Check all: <input type=”checkbox” name=”checkall” id=”checkall” value=”Check All” onclick=”Check(‘formname’,$(‘.check_list’))”>
Option 1<input type=’checkbox’ class=”check_list” name=”check_list[]” value=”1″>
Option 2<input type=’checkbox’ class=”check_list” name=”check_list[]” value=”2″>
Option 3<input type=’checkbox’ class=”check_list” name=”check_list[]” value=”3″>
</form>

The corresponding Javascript code:

function Check(form_name,chk){ // alternate check all/check none of items
if(eval(“document.”+form_name+”.checkall.value”)==”Check All”){
for (i = 0; i < chk.length; i++)
chk[i].checked = true ;
eval(“document.”+form_name+”.checkall.value=’UnCheck All’”);
} else{
for (i = 0; i < chk.length; i++)
chk[i].checked = false ;
eval(“document.”+form_name+”.checkall.value=’Check All’”);
}
}

Sort multi-dimensional array in PHP

Author: admin / Category: Programming Secrets

How to sort multi-dimensional arrays using PHP? Sorting one dimensional array is pretty easy, but to do this with two or multi-dimensional arrays, is a little different. Here is how to do it:

There’s a given 2 dimensional array:

$array[] = array(“id”=>1,”title”=>”Monkey”);
$array[] = array(“id”=>2,”title”=>”Alien”);
$array[] = array(“id”=>3,”title”=>”Stargate”);
$array[] = array(“id”=>4,”title”=>”New”);

We use the usort function of PHP:

usort($array, “cmp”);

… where cmp is the following function:

function cmp($a, $b){
return strcmp($a["title"], $b["title"]);
}

After sorting the $a array, it will look like this:

$array[0] = array(“id”=>2,”title”=>”Alien”);
$array[1] = array(“id”=>1,”title”=>”Monkey”);
$array[2] = array(“id”=>4,”title”=>”New”);
$array[3] = array(“id”=>3,”title”=>”Stargate”);

Now, the array is sorted by ‘title’ in ascending order. To sort in in descending order, just change the order of the compared elements in the cmp function:

return strcmp($b["title"], $a["title"]);

Create Excel file from PHP with tables using headers

Author: admin / Category: Programming Secrets

Did You ever needed to create pure and simple Excel spreadsheets from php? Are you tired with complicated classes, large and nonsense code? Here is a tiny code sample, showing how easy it  is to create Excel files directly from a php file. I won’t comment the lines, as the code is obvious…

$file_name = “myfile.xls”;

header(‘Pragma: public’);
header(‘Expires: 0′);
header(‘Cache-Control: must-revalidate, post-check=0, pre-check=0′);
header(‘Cache-Control: public’);
header(‘Content-Description: File Transfer’);
header(‘Content-Type: text/xls; name=”‘ . $file_name . ‘”‘);
header(‘Content-Disposition: attachment; filename=”‘ . $file_name . ‘”‘);
header(‘Content-Transfer-Encoding: binary’);

$content = ‘<table>
<tr>
<td>Header1 (A)</td>
<td>Header2 (B)</td>
<td>Header3 (C)</td>
</tr>
<tr>
<td>Content 1A</td>
<td>Content 1B</td>
<td>Content 1C</td>
</tr>
<tr>
<td>Content 2A</td>
<td>&nbsp;</td>
<td>Content 2C</td>
</tr>
</table>’;

echo $content;

Connect to strato.de with imap php functions

Author: admin / Category: Programming Secrets

Connecting to strato.de with imap isn’t easy at all, as there’s little documentations on the Internet, and they are mainly in dutch. So I will present in the following lines how you can access your e-mails from a php file.

$server = ‘{imap.strato.de:143}’;
$connection = imap_open($server, “youremail@yourdomain.nl”, “yourpassword”);

print_r(imap_errors());

$mailboxes = imap_list($connection, $server, ‘*’);

foreach($mailboxes as $mailbox)
$shortname = str_replace($server, ”, $mailbox);

imap_reopen($connection, $server.’INBOX’);

$count = imap_num_msg($connection);

for($i = 1; $i <= $count; $i++) {
$header = imap_headerinfo($connection, $i);
$raw_body = imap_body($connection, $i);
}

$server – the connection parameteres, differs from server to server. For exemple:

  • Google: {imap.gmail.com:993/ssl/novalidate-cert}
  • Google Apps: {imap.googlemail.com:993/ssl/novalidate-cert}

$connection: this is the IMAP stream

$mailboxes: will contain all the mailboxes you have (Inbox, Trash, Sent + persobal mailboxes)

$shortname: will contain just the name of the mailboxes, without their server address

imap-reopen: you can make a new stream, connecting to a given mailbox (INBOX in my case)

$count: how many mails do you have in the selected mailbox

- the last for cycle runs through the mailbox, and for every e-mail gets it’s header information ($header) and the mail’s content ($raw_body)


Powered by wordpress        .
.