WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 : 4 of 5 (graded 3 times)
Viewed : 2216
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

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

<?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
?>



PHP Script to find url links in a page
Categories : PHP, URLs, Regexps, Arrays
BBCode Formatting String
Categories : PHP, HTML, Regexps, Arrays
Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
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
Get the AppStore Ranking for any iPhone App
Categories : PHP, Web Services, Regexps
columned txt file to array()?
Categories : Arrays, Strings, Regexps, PHP
Freshmeat.net XML-RPC - This class is meant to query Freshmeat for information about registered projects.
Categories : PHP, PHP Classes, XML, Web Services
String Replacement and speed consideration
Categories : PHP, Strings, Regexps
Validating a URL with preg_match
Categories : PHP, Regexps, Beginner Guides, Data Validation
PHP Youtube Downloader - This is a set of PHP functions that can be used to download movies from Youtube.com.
Categories : PHP, CURL, Regexps
enhanced date picker with jcript checking for a dynamic date input
Categories : PHP, Java Script, Date Time, Calendar, Arrays
Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP, Arrays, Date Time, Databases, MySQL
making links from text
Categories : PHP, Regexps, Email