Friday, April 2, 2010

Change the Color & Backgraound of slected text in Browser.

I was wondering how to define color and background for text the user selects.

Try it in this in your CSS. If you select something and it will change its background to red and text to white, your browser supports selection styles.

::-moz-selection{
background:#cc0000;
color:#fff;
}

::selection {
background:#cc0000;
color:#fff;
}

code::-moz-selection {
background: #333333;
}

code::selection {
background: #333333;
}


Of course Mozilla needs a special ::-moz-selection selector, while Safari keeps it simple. The selector only seems to accept color and background. I defined a grey background for code elements with the code::[-moz-]selection syntax.

Monday, March 8, 2010

Logic to get Email From a Paragraph

My plan was to get email ids from the page posted data in PHP, it was the requirement of my module at that time to do so I write some code like this
<?php
function get_emails ($str)
{
$emails = array();
preg_match_all("/\b\w+\@\w+[\.\w+]+\b/", $str, $output);
foreach($output[0] as $email) array_push ($emails, strtolower($email));
if (count ($emails) >= 1) return $emails;
else return false;
}

# Here is how to use it.

# Sample string containing email addresses;
$str = "happy happy@gmail.com bingo happy@test.com jojo jojo@badjojo.com";

# Get the emails on arrays;
$emails = get_emails ($str);

# Print that arrays;
print_r ($emails);
?>



Output

Array ( [0] => happy@gmail.com [1] => happy@test.com [2] => jojo@badjojo.com )


Now I have given enough tips try some experimenting lust of yours and utilize it according to your need.

Thursday, March 4, 2010

JQuery Tooltip in easy Move...

The Tooltip is a common graphical user interface element. It is used in conjunction with a cursor, usually a mouse pointer. The user hovers the cursor over an item, without clicking it, and a tooltip may appear — a small "hover box" with information about the item being hovered over.


This type of tooltip can be generated in different ways.We will see all of them later.
To create Tooltip you have to download Jquery tooltip Plugin from:

Download ToolTip Plugin

Select Development and Jquery check boxes. Thats enough to keep tooltip working. Thats what I prefer but you can download all :).



Now you will be able to see "jquery.qtip-1.0.0-rc3.custom.zip" compressed file in your download folder. Extract it -> Open it. Here you will find following files.

  1. jquery-1.3.2.min.js -> Compressed Jquery File
  2. jquery.qtip-1.0.0-rc3.min.js -> Compressed Plugin File.
  3. jquery.qtip-1.0.0-rc3.js -> Main Tooltip Plugin file.
  4. INSTALL -> File for install instructions
  5. REQUIREMENTS ->File to tell you abut the requirement of the tooltip to run.
  6. LICENSE-> Licence Agreement file.
Here I wanna tell you that you need not to read any file. Just keep reading.....
Now Create a html file with following code and save it in the same folder where other six downloaded files exists....

<html>
<head>
<title>
jQuery Tooltip Plugin
</title>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquery.qtip-1.0.0-rc3.js"></script>

<script type="text/javascript">
$(document).ready(function()
{
$('#computercurry a[href][title]').qtip({
content: {
text: false
},
style: 'dark'
});
});
</script>
</head>


<body>
<h1 style="{ padding: 15px; background-color: #96b; color: white; font-size: large; border-bottom: 1px solid #ccc; text-align: center }"><a href="http://computercurry.blogspot.com/" style="color:white">jQuery Tooltip Plugin</a></h1>

<fieldset id="computercurry">
<legend>Using bodyHandler to display footnotes in the tooltip</legend>
<a href="http://computercurry.blogspot.com/" title="This is the link to 'Computer Curry' Blog">Move your mouse to this link</a>
</fieldset>

</body>


Now you can see it is Displaying tool tip in new format when you move your cursor on LINK.

Now, Some Good thing to know you can alter the way tooltip appears. By default it is "dark" but u can change it to other styles too... like "green", "blue", "red", "dark" and "cream". what you need to do is just change the value of "style: 'dark'" to "style: 'blue'" or any color from this list and see the magic.

Now you only need to do is keep experimenting and see you alter it. Also this tooltip can be applied to all html tags that supports "title" parameter. ;) Do experiment and know how?


Waiting for your comments....

Tuesday, February 16, 2010

Date Convertion in PHP... Easy Move..

In this code we are capable to give Source date format and Destination date format as parameters our function of date conversion.

As in this example:
Source Format: 'd/m/Y';
Destination Format: 'Y-m-d';
Input Date: "25/12/2005";
Output Date: "2005-12-25".


[?php //Php start tag...
/**
* Converts a date string from one format to another (e.g. d/m/Y => Y-m-d, d.m.Y => Y/d/m, ...)
*
* @param string $date_format1
* @param string $date_format2
* @param string $date_str
* @return string
*/
function dates_interconv( $date_format1, $date_format2, $date_str )
{
$base_struc = split('[/.-]', $date_format1);
$date_str_parts = split('[/.-]', $date_str );

$date_elements = array();

$p_keys = array_keys( $base_struc );
foreach ( $p_keys as $p_key )
{
if ( !empty( $date_str_parts[$p_key] ))
{
$date_elements[$base_struc[$p_key]] = $date_str_parts[$p_key];
}
else
return false;
}

$dummy_ts = mktime( 0,0,0, $date_elements['m'],$date_elements['d'],$date_elements['Y']);

return date( $date_format2, $dummy_ts );
}

$df_src = 'd/m/Y';
$df_des = 'Y-m-d';

$iso_date = dates_interconv( $df_src, $df_des, '25/12/2005');
?>


output:

2005-12-25

Sunday, February 7, 2010

Blank admin page in Drupal 6

I installed Drupal 6 today on my windows machine in office. After creating the first user I tried to access the Administration Page, but a blank page was returned. I searched google to fix this problem.. What I found was totally helpful... as it solve my problem.

If you too facing such problem then just what you need to do is:-

Go to "system" table of you Drupal Database and change the value of 'status', 'bootstrap' and 'throttle' to 0. By using PHPMyAdmin or MySql Command line:


update system s
set s.status=0, s.throttle=0, s.bootstrap=0
where filename = 'modules/update/update.module'


This help me to access my Drupal's admin panel hope this will help you too.

:)

Sunday, January 18, 2009

JSP vs PHP

Not to cause a flame war, but recently I compared JSP with PHP and here is what I got.

Sr. No.

Function / Feature

JSP

PHP

1.

Programming Approach

Completely object oriented

Advantage: Clean code

Disadvantage:

Too descriptive

Scripting with object oriented support

Advantage: Functional and quick coding, you can use OOP practices at your convenience

Disadvantage: May get clumsy

2.

String and data manipulation

Rich library, too much descriptive and object oriented code

Rich functionality. Functional and easy coding.

3.

Web Oriented features

  1. Includes
  2. Mails
  3. File Uploads
  4. Form Handling
  5. Sessions

Almost everything is built in or supported by libraries. Complicated and too much of code.

Inbuilt functionality. Easy to use functions, written for the specific tasks

4.

Database Access features

Standard JDBC structure/ Use EJB/ Struts framework built over JDBC. Descriptive and too much overhead or boiler plate code involved. Uses the same API for all databases using JDBC drivers

Dedicated inbuilt libraries for most of the commonly used databases. Very tight integration with MySQL and PostGRESQL. Very minimal boiler plate code required. The libraries and results are straight forward and easy to use.

5.

XML/XSL/XPATH

Use standard SAX/DOM parsers. Too much boiler plate code involved. Well defined APIs and stable implementations are available for XSL and XPATH

SAX and DOM parsers available are easy to use and to the point. Another library, Simple XML provides very easy OO approach to handling XML data. XSL and XPATH functionality is also built in.

6.

Extensibility

Java Classes and Libraries. Run’s in sandbox and hard JNI approach needed to integrate with server programs.

PHP/C/Any thing executable by the underlying OS platform. Can very easily interact with programs on the server. Very good support for native code.

7.

Dynamic Graphics/PDF and bells and whistles

Almost everything has a readymade library

Supported internally or though libraries.

8.

Web Services/SOAP

Addon Libraries like Axis, JAX-WS, etc.

In Built

9.

Portals

Spec JSR-168 and 286

Many different Portal frameworks

Conclusion:

I have generally found that anything can be down in both the languages. Just while working with the Web Applications, PHP tends to do easy things the easy way and also manages difficult things in a fairly decent manner. JSP, being built over Java, a generic OOP language, involves more structure and coding.

Generally observed in my past experiences and by most of people who have worked on both platforms is production in PHP is quick as compared to Java. But maintenance of PHP code tends to be difficult due to lack of constraints on the developer for structuring the code. But this can be made over by following proper coding guidelines.

The lack of tooling for PHP is also many a times a concern.

But overall, PHP is much more well established with libraries, frameworks, patterns and code base for general Web Dev, while java’s base is much more standard’s oriented. For example we can take the Portals. Java has a standard Portal Spec, while PHP has hundreds of Portals/Frameworks available not conforming to any standard.

A note about the libraries:

Though Java tends to be very much standard oriented, there isn’t much effort on the community or user or promoter’s side to organize/gather/test generic or readily available libraries.

The PEAR project for PHP libraries hosted at http://pear.php.net/ provides a large library for PHP, most of which are actively developed and tested and in production use.

Gut feeling, there is a library for everything on both platforms. Java is much more commercialized than PHP. So chances of getting a free to use, unrestricted and one source PHP library is easier than for Java.

There are many implementations for similar tasks to be done. A central location like PEAR is a good pointer to have.

Design pattern wise, like for MVC, also both platforms have libraries available. The functionality and approaches vary from library to library.

There can’t be a more stronger reason to suggest the scripting benefits than JSR 223, which plans to bring Scripting languages, specially PHP to J2EE.

With a vast number of frameworks easily available, PHP shall be my obvious choice for websites and portals.

I will prefer Java or may be .Net depending on various factors for Web Based Applications, because, they are more structured and easy to maintain and moreover may be just because they have the enterprise appeal and wide array of tools.

One major consideration while this decision is availability of developers for the platform, which is much larger for Java.