We all search for stuff and most of us use Google for our searches. Ability to search Google more efficiently will save you a lot of time. Thus, if you feel like saving some of your precious time and pulling the results you want, use some of these tips to make your searches more effective. Some of these might be obvious yet very significant. You should always think about using either/or operators, quotes for exact phrase, or “-” symbol to minus a phrase from your search. If you only use these three tips, your search results will be ten times better. Consider an example.
If you just type in Paris Hilton into the search, the results will include all the words: websites that talk about places like Paris, France and websites that talk about people like Nicky Hilton. This is not so obvious with Paris Hilton as an example because she is a very popular celebrity but it’s very evident when searching something with fewer results. So, if you want to see websites that only talk about the actual celebrity, you can add quotes to your search (”Paris Hilton”) and get results for the exact phrase. You can also use minus to not include certain phrases in your search. Searching “Paris Hilton” –jail should remove the websites that talk about Paris Hilton being in jail. If you want to search for one term or another, you can use the OR operator – or | as in Paris | Hilton which provides results about the term Paris or the term Hilton.
If you arrived on a page that is outdated or changed, it might be useful to search Google’s cache. Use the “cached:” operator to search for a version of a page the Google stores on its own servers. If you want to search for similar terms, you can use the “~” symbol. Searching for ~anorexic Nicole Richie -anorexic will result in pages that contain “thin Nicole Richie” and “skinny Nicole Richie” but not “anorexic Nicole Richie.” The “*” symbol is a wildcard and it can be used to search for a part of a phrase that you do not remember. If you want the lyrics to Paris Hilton’s song “Stars are Blind” and you only recall a part of the lyrics and search Even though the * are crazy you will get some of the proper results. The wildcard is also useful for finding stuff in only certain domains, for example *.edu to search only educational websites.
To search only within a certain website, use the “site:” operator. For example, site:music.com Paris Hilton will search for Paris Hilton only within the music.com domain. All the results will point to that domain. The “link:” operator will find results that link to a particular URL. If you are searching for a list of movie show times close to your zip code, you can use the “movie:” operator. For example, movie: knocked realizes that I am looking for the movie “Knocked Up” and displays the movie information, links to trailer, IMDB, and reviews. Once you select a zip code, you can see all the movie listings near you. There is also the “music:” operator that displays only music content. For example, music:Paris Hilton will only provide Paris Hilton’s music information.
Did you know that you can search for content in particular file types on Google? If you want to see information about Paris Hilton only in pdf files you can use the “filetype:” operator. The following search Paris Hilton filetype:pdf results in content about Paris Hilton taken only from PDF files. You can also search for your term in certain locations within websites using operators such as “inurl:”(only within the URL), “intitle:”(only within the title), “intext:”(only within the text), and “inanchor:”(only within the anchor text that describes a link). For example, intitle:Paris Hilton will display websites that only have Paris Hilton in their titles.
Google Search can also be used to for definitions and calculations. Use the “define:” operator to get a quick definition. define:celebrity will list a couple definitions from various sources with links. Use the +, -, *, / symbols and parentheses to do a simple equation. For example, 2+2 will perform the calculations and it’s much faster then loading the computer’s calculator. For other calculations, such as conversions you can use the “in” operator. For example, 12 usd in euro converts 12 USD to euro and 12 meters in yards converts 12 meters to the value in yards.
You can also search for a range of numbers. The “..” symbol is used for range and if you search for Paris Hilton 2002..2004 it will return websites that connect information about Paris Hilton and the years 2002, 2003, and 2004. Google’s algorithms can also distinguish patterns in numbers you enter, so you can search for things like weather forecast, telephone area codes, stock quotes, UPC codes, Vehicle ID numbers (US), Federal Communications Commission (FCC) equipment numbers (US), Federal Aviation Administration (FAA) registration numbers (US), Patent numbers (US), etc. For example, searching for GOOG results in Google’s stock information on the top of the search and websites below.
Finally, you should consider doing a vertical search or using Google’s Advance Search. Vertical Search refers to searching within a particular field instead of searching for a term across the entire web. If you are searching for something that is covered in Blogs, you can search Google’s Blog Search or if you want to only search for images, you can search Google’s Image Search. There are also tips for searching within these specific fields, such as searching for faces in image results by adding the following text string to the end of the URL: &imgtype=face. If you only want to see Paris Hilton’s face, try the following search. Notice the &imgtype=face added to the end of the URL. In the end, try using Google’s Advance Search.
Friday, February 18, 2011
Tips for Better Google Searches
Wednesday, February 16, 2011
Retrieving Data from MySQL DataBase with PHP
A ton of websites use PHP and MySQL for web development and most of the time they are built around some Content Management System that handles database interaction. However, if you are interested in learning how to simply interact with the database using php, then I will provide a nice example. The PHP mysql_fetch_array() function returns an array of the requested data from the table. Then, a while loop assigns a row’s data to an array called $row and the value associated with the column name on each row is written out. The following php code is modified from a Mike McGrath’s PHP for WINDOWS and LINUX book:
[sourcecode language="php"]
<html><head><title>Get Data</title></head>
<body>
<?php
#connect to MySQL
$conn=@mysql_connect("localhost","user","password") or die("Err:conn");
#select the specified database
$rs=@mysql_select_db("database_name", $conn) or die("Err:Db");
#create the query
$sql="select id,cat_name from table";
#execute the query
$rs=mysql_query($sql,$conn);
#write the data
while( $row = mysql_fetch_array($rs) )
{
echo("ID: ".$row["id"]);
echo(" Print Data: ".$row["cat_name"]."<br>");
}
?>
</body>
</html>
[/sourcecode]
I tested the script and it works great. Make sure that the table exists in your database and it has what you are trying to pull. I had something under id and something under cat_name in my table so it showed me the appropriate values. If you have questions, send me an email or comment.
[sourcecode language="php"]
<html><head><title>Get Data</title></head>
<body>
<?php
#connect to MySQL
$conn=@mysql_connect("localhost","user","password") or die("Err:conn");
#select the specified database
$rs=@mysql_select_db("database_name", $conn) or die("Err:Db");
#create the query
$sql="select id,cat_name from table";
#execute the query
$rs=mysql_query($sql,$conn);
#write the data
while( $row = mysql_fetch_array($rs) )
{
echo("ID: ".$row["id"]);
echo(" Print Data: ".$row["cat_name"]."<br>");
}
?>
</body>
</html>
[/sourcecode]
I tested the script and it works great. Make sure that the table exists in your database and it has what you are trying to pull. I had something under id and something under cat_name in my table so it showed me the appropriate values. If you have questions, send me an email or comment.
Thursday, February 10, 2011
Best jQuery Modal Box Plugin
These days we see Modal Windows everywhere and they are a great way to present information to our viewers. If jQuery is your JS library choice then you have lots and lots of choices of different jQuery modal box plugins. But, you just need one, a good one, so what is the best jQuery Modal Plugin?
Obviously, opinions will vary here, but I can tell you the top choices, plugins I have used on real production web sites. Many people point to the jQuery UI modal and for good reasons, it has many options and it is part of jQuery UI, so if you are using it, there is no need to load extra javascript. But, I don't personally like it, probably because I rarely use jQuery UI and if you are not using it, then you don't want all that JS for just a modal script.
That is the point, a modal is a pretty simple concept, you really don't even need a jQuery plugin, you could just write it yourself. But, if you are supporting IE browsers and need good cross-browser consistency, then a small modal box plugin is a good idea. But it needs to be small, simple, and well written. And it should also be plug and play right out of the box.
I have seen Facebox used on a couple websites and even though at first it seemed like a great little modal box plugin, now I think it's not that great. Quick plug and play installation (call the script in head and call the modal box function on document load) revealed to me that the close and loading images where not showing up. So, I need to configure the call, which is fine, but the damn thing should just work out of the box.
When looking at the script I realized that those two images where not showing up because the img src tag had a bad url configuration, and even though it is nice that the plugin allows you to neatly configure these urls, I think that such images should be image tags but background images referenced in css and there pointed to the correct image, thus, not needing any configuration.
So, not impressed so far with the way this plugin was put together, but I changed the configuration and I could now see the close image but the loading image was still not showing up. Looking at the code again I realized that there is a problem, the overlay html code (which is part of the facebox javascript) is missing an element
[sourcecode language="html"]
<div class="body">
[/sourcecode]
which is later referenced in the JavaScript. If you were not loading Ajax content into the modal you would have probably not noticed this, but I need Ajax. If you still cannot get Facebox loading image to show up, take a look at these comments. Anyways, this is a good example of a modal box plugin that I want to stay away from, you can easily fix it and configure it, but I want something much better out of the box.
I have looked at a couple other jQuery modal plugins that have been suggested by many people and here is a list of 5 that I found to be almost perfect:
ColorBox - lots of options, images via css background, support for older browsers, well written and often updated.
BlockUI - also lots of options and it has many good examples to look at before using the plugin.
FancyBox - it gives you a really neat Mac-style presentation with a ton of options in its API.
ShadowBox - another well written, highly customizable modal box plugin that supports all major browsers.
NyroModal - this one has a crazy amount of options
The last one, nyroModal, maybe should not have been mentioned, because it has so many options that it is no longer really a simple modal jQuery plugin. However, I have seen it implemented on many popular websites and it is damn powerful, so if you are looking for lots of options, that could be the winner for you.
But I am still looking for something simple yet well customizable and quickly plug and play. For me, the winner is SimpleModal. It has all the options I need, I can make style changes via css, and it is small and works out of the box. I have used it on some big production websites with great results. So, there you go, I think that SimpleModal is the best jQuery Modal Box plugin today.
Obviously, opinions will vary here, but I can tell you the top choices, plugins I have used on real production web sites. Many people point to the jQuery UI modal and for good reasons, it has many options and it is part of jQuery UI, so if you are using it, there is no need to load extra javascript. But, I don't personally like it, probably because I rarely use jQuery UI and if you are not using it, then you don't want all that JS for just a modal script.
That is the point, a modal is a pretty simple concept, you really don't even need a jQuery plugin, you could just write it yourself. But, if you are supporting IE browsers and need good cross-browser consistency, then a small modal box plugin is a good idea. But it needs to be small, simple, and well written. And it should also be plug and play right out of the box.
I have seen Facebox used on a couple websites and even though at first it seemed like a great little modal box plugin, now I think it's not that great. Quick plug and play installation (call the script in head and call the modal box function on document load) revealed to me that the close and loading images where not showing up. So, I need to configure the call, which is fine, but the damn thing should just work out of the box.
When looking at the script I realized that those two images where not showing up because the img src tag had a bad url configuration, and even though it is nice that the plugin allows you to neatly configure these urls, I think that such images should be image tags but background images referenced in css and there pointed to the correct image, thus, not needing any configuration.
So, not impressed so far with the way this plugin was put together, but I changed the configuration and I could now see the close image but the loading image was still not showing up. Looking at the code again I realized that there is a problem, the overlay html code (which is part of the facebox javascript) is missing an element
[sourcecode language="html"]
<div class="body">
[/sourcecode]
which is later referenced in the JavaScript. If you were not loading Ajax content into the modal you would have probably not noticed this, but I need Ajax. If you still cannot get Facebox loading image to show up, take a look at these comments. Anyways, this is a good example of a modal box plugin that I want to stay away from, you can easily fix it and configure it, but I want something much better out of the box.
I have looked at a couple other jQuery modal plugins that have been suggested by many people and here is a list of 5 that I found to be almost perfect:
ColorBox - lots of options, images via css background, support for older browsers, well written and often updated.
BlockUI - also lots of options and it has many good examples to look at before using the plugin.
FancyBox - it gives you a really neat Mac-style presentation with a ton of options in its API.
ShadowBox - another well written, highly customizable modal box plugin that supports all major browsers.
NyroModal - this one has a crazy amount of options
The last one, nyroModal, maybe should not have been mentioned, because it has so many options that it is no longer really a simple modal jQuery plugin. However, I have seen it implemented on many popular websites and it is damn powerful, so if you are looking for lots of options, that could be the winner for you.
But I am still looking for something simple yet well customizable and quickly plug and play. For me, the winner is SimpleModal. It has all the options I need, I can make style changes via css, and it is small and works out of the box. I have used it on some big production websites with great results. So, there you go, I think that SimpleModal is the best jQuery Modal Box plugin today.
Tuesday, February 8, 2011
Six Ways to Redirect Visitors to a New Url
PHP, JavaScript, META and Htaccess Redirection
Do you need to redirect your users to another page? There are a six different ways you can get it done, two methods using PHP, two methods using JavaScript, and one way using META Refresh or via htaccess file. There are different reasons for using different methods. Here is the code with some explanations:
1. Direct PHP Redirect: This is a direct redirection using server side PHP code without any delay. No client side code is processed (no infomation is sent to the browser), the user is immediately taken to the page specified in the PHP file.
[sourcecode language="php"]
header("Location: http://www.example.com/"); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
[/sourcecode]
2. PHP Redirection with Delay: This is a PHP redirect with a specified delay in seconds. During this delay, PHP code can be processed and passed to the browser. Using the code below, the user will see the message “You will be re-directed in 5 seconds…” for 5 seconds before the browser redirects user to the page specified.
[sourcecode language="php"]
header( "refresh: 5; url=http://www.example.com/" );
echo "<h1>You will be re-directed in 5 seconds…</h1>";
[/sourcecode]
3. JavaScript Direct Redirection: If you don’t know PHP you can use JavaScript to redirect. JavaScript is done on client side so it even though this is a direct redirection, it can still send information to the browser. This means that you can process some javascript and then redirect the user, or redirect the user based on some process; in the first example of PHP direct redirection you cannot process anything on the client side.
[sourcecode language="JavaScript"]
window.location = "http://www.google.com/"
[/sourcecode]
4. JavaScript Redirection with Delay: This is almost the same as the direct javascript redirection shown above, however, here you can specify a delay time similar to the delay time specified in the second PHP example. 5000 means 5 seconds.
[sourcecode language="JavaScript"]
setTimeout("location.href=’http://www.google.com/’", 5000);
[/sourcecode]
5. Meta Refresh Redirection: This redirection method uses a HTML meta element to tell the web browser to automatically redirect the user to another web page after some time. According to W3C, it is bad practive to use META to redirect becasue it does not give any info about either the original or new resource to the browser or search engine. The “back” button will also not work in some browsers. But, it’s still another way to get the job done.
[sourcecode language="html"]
<meta http-equiv="refresh" content="5;url=http://www.google.com/" />
[/sourcecode]
6. Htaccess Direct Redirectionn: My favorite way of redirecting is by using the .htaccess file. It has no delay because it is done server side and visitors get sent directly to the new page before the original page is server to the browser. Here are some ways of redirecting using the htaccess file (301 means Moved Permanently):
To Move a single page:
Redirect 301 /old-web-page.html http://www.example.com/new-web-page.html
To Move an entire site:
Redirect 301 / http://www.example.com/
Redirect www to non www version of site:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule (.*) http://example.com/$1 [R=301,L]
Redirect non-www to www:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
Tuesday, February 1, 2011
Regular Expressions - Resources, Samples, and Regex Information
Regular Expressions are a really powerful, useful, and precise means for matching strings of text via a given pattern. They are also referred to as regex or regexp. If you have been doing any kind of development, front-end or back-end, you have probably used or seen them in action. In the front-end world, form validation comes to mind right away, but there are many uses, and it's a good idea to have some fundamental knowledge about regular expressions.
In this article I will try to provide some of the best links to resources available on the internet for regular expression tutorials, tools, patterns, and regex information. I hope it will be helpful to anyone that wants to learn more about regex or someone that is just looking for a pattern for their code. If you prefer to read a real book instead of looking at online text, I would definitely recommend Mastering Regular Expressions by Jeffrey Friedl.
As a start, I think a good place to begin learning about regular expressions is glancing at the wikipedia regex entry. Wikipedia gives you a good overview of basic concepts, history, and some good regular expression patterns and metacharacters to remember. After you have this overview, the best place to learn about regular expressions online is definitely the regular-expressions.info website. Most people that work with regular expressions daily always recommend this site as a super informative resource. Also, while you are getting introduced to regex, download a regular expression cheat sheet.
Learning Regular Expressions
If you are looking for more explanations on why and how things work in the world of regex, I would recommend these links:
How to Regex
Mastering Regular Expressions
PHP Regular Expressions
Regular Expressions for SEO
Learning Regular Expression Patterns and Samples
Most people don't really want to learn regular expressions but they are searching for a pattern for their code and need a good resource to find good regex samples and examples. The obvious problem with that is that you are just taking a guess that the pattern is good without really knowing what you are doing... but these resources are really good and provide many patterns with explanations and helpful descriptions. Also, looking at these patterns can help you learn more about regular expressions:
Regex Patterns
JavaScript Regex
Regular Expressions for Web Developers
Intro to PHP Regex
Programming Regular Expressions
Password Strength Regex
URL validation via Regex
Online Regex Testers
While you are reading about regular expressions and browsing through patterns, you probably want to try some of these yourself. Well, there are many options, you could write a quick regex tester yourself in PHP, JavaScript, or whatever language you are most comfortable with, but why not just try one of the many online regular expression tools available on the internet. Here is a list of great regex online editors (most of these have some good information and sample patterns that you can test out for yourself):
gSkiner RegExp
Rubular
RegTest Tester
Regex Pal
Regex Editor
Regex Tool
Finally, if you are looking for even more links and information on regular expressions, I think these two articles do a good job on giving you extra resources:
Essential Guide to Regular Expressions
You don't know anything about Regular Expressions
Subscribe to:
Posts (Atom)