Pages

Friday, December 30, 2011

Those little useful tools

Today I'm going to share 2 tools with you. I've found these tools very useful as I go about my work at ZoomTanzania.com.

The two tools are:
When you copy content from one html page into a text editor in another page, the html and the styling of that content comes along with the copied content. For example:

<ul>
<li><h2 style = 'font-size: 20px; font-weight: bold'><a href = 'http://www.hello-world.com'>Hello world</a></h2></li>
<li><h2 style = 'font-size: 20px; font-weight: bold'><a href = 'http://www.phprocks.com'>PHP Rocks</a></h2></li>
</ul>

Well, but I don't need all those extra tags, I only need <a href = 'http://www.hello-world.com'>Hello world</a> and <a href = 'http://www.phprocks.com'>PHP Rocks</a>. 

So what you do is to copy and paste the code into Zubrag.com' HTML Tags Stripper, and just specify which tags you want to remain, and it will do the rest. Great tool.

MAILCHIMP'S HTML TO PLAIN TEXT CONVERTER
I used MailChimp, (MailChimp is amazing) and I must say I've always enjoyed their HTML to plain text converter. For those who may not know, plain texts can be used for many purposes. I need a plain text version for the Newsletters I develop at ZoomTanzania.com. It is recommended to include a plain text version of a campaign email, just in case there are people using text-only browsers or using a mobile phone, or those who use mail clients that disable links and images... Anyway, it's useful for someone.

Right now I use Rahisisha Mail to organize the newsletter, and their package doesn't include an HTML to Plain Text converter. I've had to do this manually, and it adds to the time I spend to make the newsletter. However, just today I realized that Mailchimp's HTML to Plain Text Converter is available for use by the public. Now isn't that great? Just do all your HTML coding and then copy and paste the code into Mail Chimp's converter and voila, you have your plain text version.

html2txt
You may also want to try html2txt... I've not tried it yet, because I'm running short of time, but I think it is good.

Hope this post is useful to someone! 

Wednesday, December 28, 2011

Removing Values from a PHP Array

I found myself needing to remove a couple of values from a PHP array. There's currently no PHP function that removes a value from an array, but there's a way around it.

You're going to need the following functions:
  • array_search
  • unset

ARRAY_SEARCH
The array_search function, can take up to three arguments. But you'll only need 2 for this to work.

syntax: array_search (needle, haystack);

where 
  • needle = what you're searching for
  • haystack = where you're searching from
 This functions returns the array key of the first occurrence of the needle in the haystack (there may be multiple occurrences)


UNSET
The Unset function unsets the value of a variable.

Therefore, to remove values from an array, one would do something like this:
<?php
$emails = array ('hello@world.com', 'hi@hello.com', 'greetings@greet.com');
$find = 'hello@world.com';

$key = array_search($find, $emails);
unset($emails[$key]);

?>

You're done! Obviously, if you have to find many emails, you'd have to put those emails in an array, and do a foreach. Something like this:


<?php
$emails = array ('hello@world.com', 'hi@hello.com', 'greetings@greet.com');
$find = array( 'hello@world.com', 'hi@hello.com');

foreach($find as $find_email)
{
     $key = array_search($find_email, $emails);
     unset($emails[$key]);
}
?>

Easy isn't it?