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