WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : grab the result of any calculation you submit to the Google Calculator.
Categories : PHP, Arrays, Web Services, Regexps, Math. Click here to Update Your Picture
Alix Axel
Date : Apr 28th 2009
Grade : 3 of 5 (graded 2 times)
Viewed : 1302
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Alix Axel
Action : Grade This Code Example
Tools : My Examples List

 
Like this code?
Show the author your appreciation.
Submit your own code examples 
 

<?php

function Google_Calculator($query)
{
   
$matches = array();

    if (
preg_match('~<b>.+? = (.+?)</b></h2>~', file_get_contents('http://www.google.com/search?q=' . urlencode($query)), $matches) > 0)
    {
        if (
array_key_exists(1, $matches) === true)
        {
            return
$matches[1];
        }
    }

    return
false;
}
?>



Usage:
<?php
Google_Calculator
('2 + 2'); // 4
Google_Calculator('5 + 5 * 10'); // 55
Google_Calculator('(5 + 5) * 10'); // 100
Google_Calculator('1 USD to EUR'); // 0.768816791 Euros
Google_Calculator('1 EUR to USD'); // 1.3007 U.S. dollars
Google_Calculator('the answer to life, the universe and everything'); // 42
?>



Check for functional file links (broken Files)
Categories : PHP, Data Validation, FTP, Regexps, Arrays
Weighted Random - Random Scripts usually chose one out of each item, and each item have an equal chance to be chosen. But what if you want an item to be chosed more frequently than other?
Categories : PHP, Math., Arrays
Stock quotes from yahoo!
Categories : PHP, Web Services, Arrays
columned txt file to array()?
Categories : Arrays, Strings, Regexps, PHP
Get the AppStore Ranking for any iPhone App
Categories : PHP, Web Services, Regexps
BBCode Formatting String
Categories : PHP, HTML, Regexps, Arrays
PHP Script to find url links in a page
Categories : PHP, URLs, Regexps, Arrays
Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
Variable serialization and unserialization. Loading and saving variable structures to and from file.
Categories : Arrays, Filesystem, Variables, Strings, PHP
Latitude-Longitude to Miles
Categories : PHP, Utilities, Math.
Extract keywords from a string having words in " " count as one string.
Categories : PHP, Strings, Regexps, Search
Math operations on big numbers
Categories : PHP, Math.
Simple way of scaling any image to fit either given width or height.
Categories : PHP, Graphics, Arrays
PHP Random rss feeds - selects 49 random feeds from an unlimited list and displays them on your website. It's Ideal for those moments when you got 5 minutes and dont know which one of your feeds to read.
Categories : PHP, Rich Site Summary (RSS), Arrays
WWW interface to Unix Manual(phpMan)
Categories : Program Execution, Strings, Arrays, PHP