Thursday, September 30, 2010

Trim a string up to character limit without word cut in PHP

Lots of times when you're developing a site, you'll want to have a snippet of text in one place. PHP doesn't really have a good way of doing this because different languages have different definitions of "words", and a space-character is not always the delimiter between words, as it is in most Latin-based languages.

But for those of us speaking languages that stick spaces between words, clients will often ask us to "just show the first 10 words" here or there. So here's a handy PHP function to do just that.

This function can be used to trim a long string up to a given character limit/count without the last word not being cut half.



function trim_me($content, $limit){

$content = substr($content, 0,$limit);
 
$wordlimit = 1000;

$content = explode(' ',$content);

for($i=0; $i<$wordlimit; $i++) $summary[$i] = $content[$i];

$summary = implode(' ', $summary).'...';

return $summary;

}

?>

Sample Usage:

trim_me($sample_string,10);

Could not find the file flash.ocx - FIX

Some third party screen savers are designed to make use of the flash player software when running.

Which results in the errors such as;
  • “Could not find the file flash.ocx”
  • cant find file flash.ocx
  • cannot find file flash ocx
To fix this simple problem,

1. Browse to the C:\Windows\System32\Macromed\Flash folder.
2. Locate the flash9.ocx or flash10.ocx or similar flash[*].ocx file and make a copy of that file.
3. Rename the new copied file to flash.ocx
Voila Done !!!

Thursday, September 2, 2010

Firebug v/s Dragonfly

Opera Dragonfly has just been released. Just goto http://dragonfly.opera.com
and check it out now. This is the alpha version of our developer tools,
so be keep in mind that more and more features will come in the future
as well.

Opera Dragonfly is available from Tools/Advanced/Developer Tools, in Opera 9.5 beta 2 and above.

The
alpha release includes the initial implementation for the JavaScript
Debugger, CSS Inspector, DOM Inspector, Command Line and the Error
Console, as well as the Scope module, which allows Opera Dragonfly to
communicate with the Opera browser. This second alpha in the coming
weeks, will add inline editing support, improved remote debugging,
improved threading in the JavaScript Debugger and infrastructure for
localisation.

One of the key reasons for the alpha release is
to collect feedback from developers, to gauge how Opera Dragonfly
covers their needs. We will use this feedback to improve Opera
Dragonfly as it moves into beta and then full release.

Feedback can be given at http://www.opera.com/products/dragonfly/feedback/

The Opera Dragonfly blog is at http://my.opera.com/dragonfly/blog/

You can read about the current features at http://www.opera.com/dragonfly/

For more information you can visit http://dragonfly.opera.com

Popular Posts