Blogvaria

This page is brought to you by Blogvaria (http://blog.evaria.com).

To obtain more information, ask questions and interact please visit our website.

Back to Blogvaria landing page
Feedback
Subscribe
   
Blogvaria

 

The personal pages

Archive for Programming

Using PHP to print only the first sentence

Ever wanted to pull just the first sentence of a text and print it? If yes, this is for you.

Simply add the following code (in PHP) to your page/system before the actual HTML stuff begins:

< ?php
function getFirstSentence($string)
{
    // First remove unwanted spaces - not needed really
    $string = str_replace(" .",".",$string);
    $string = str_replace(" ?","?",$string);
    $string = str_replace(" !","!",$string);
    // Find periods, exclamation- or questionmarks with a word before but not after.
    // Perfect if you only need/want to return the first sentence of a paragraph.
    preg_match('/^.*[^\s](\.|\?|\!)/U', $string, $match);
    return $match[0];
}
?>

Then call the function somewhere on the page where you want the text to appear:

< ?php
    // The $string below could/should be a text string pulled from your database or similar
    $string = "Lentence oneasdasd asd asd asdasd, ?. Sentence two? Sentence three! Sentence four.";
    echo getFirstSentence($string);
?>

Comes in handy for search result pages, page titles and similar listings.

Filed under Programming | No Comments

How to remove the active/focus borders

I’m sure you have noticed that when you click a hyper link, and especially a linked image, a dotted border appears around it. Have a look at CSSplay for more examples and proper CSS code fix related to this.

A few quick solutions

For those of us using the jQuery Java framework the “solution” is incredibly simple. Just call the following function in your header and all dotted borders are gone:

jQuery("a").focus(function(){this.blur()});

Using CSS it’s almost as simple (at least for all browsers except IE):

a:focus {outline-style: none;} 

Using basic JavaScript the following should do the trick:

for(var i=0;elm=document.links[i];i++)
{
elm.onfocus=function(){elm.blur();};
}

Some would probably say that this shouldn’t be done because the active/focus dotted border is there to show visitors who are using tabbed link selection which link is selected. But when we are using CSS we can style our own active/focus state and in this case the dotted border is not so necessary. I’ll appreciate your take on this as I’ve debated this “issue” with some of my clients on several occasions.

Filed under CSS & Design, Programming | No Comments

Introducing SWFObject v2

SWFObject is an easy-to-use and standards-friendly method to embed Flash content, which utilizes one small JavaScript file. I’ve previously mentioned SWFObject in one of my posts last year.

The latest release is now featured on Google code, and from my initial testing it appears to be flawless.

Filed under Programming | No Comments

Another browser detection method

First let me emphasise that I’m not a big fan of making up different styling rules for the various browsers. But in some (most) cases it’s an absolute necessity.

Before I continue I’d like to mention Dean Edwards IE7 JavaScript library which makes Microsoft Internet Explorer behave like a standards-compliant browser. It fixes many HTML and CSS issues and makes transparent PNG work correctly under IE5 and IE6. That saves you the hassle of making tons of IE specific style sheets and embedding them using these conditional comments (bottom of page).

So with IE out of the way there’s still a few Opera and Safari “bugs” that may need attention. Instead of relying on JavaScript, which will be ignored by some browsers or users that have disabled Java, you may try this PHP approach that I successfully implemented on one of my sites today.

Full story | Filed under CSS & Design, Programming | No Comments

Introducing markItUp!

markItUp! is a JavaScript plugin built on the jQuery library. It allows you to turn any textarea into a markup editor. Html, Textile, Wiki Syntax, Markdown, BBcode or even your own Markup system can be easily implemented.

markItUp!

markItUp! is not meant to be a “Full-Features-Out-of-the-Box”-editor. Instead it is a very lightweight, customizable and flexible engine made to meet the developer’s needs in their CMSes, blogs, forums or websites.

Note! markItUp! is not a WYSIWYG editor, and it never will be.

Visit Jay Salvat for more information, examples and to download the source.

Filed under CSS & Design, Programming | No Comments


Page 1 of 1312345678»...Last »

Quick links - Blogvaria time links [ sitemap ]

2010 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec

2009 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec

2008 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec

2007 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec

2006 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec

Akismet has protected Blogvaria from 115,802 spam comments. Design by Evaria.com. Powered by WordPress.
Our beloved and trusted server has rendered 587 pages so far today, an amazing 3.326 pages yesterday
and even more astonishingly 285.726 pages since 09 Jun 2010 alone without dropping a byte nor a pixel.

Close
E-mail It