Category ‘PHP‘

 
 

cURLing Google for Fun and Profit

Here is an example of brute force engine searching. It does nothing more than perform a large number of searches in a very short time. Beware this is not a very nice thing to do and it is a terrible waste of network, and CPU resources. This is given as an example of the power of cURL. This script is written in PHP and uses the libcurl libraries.
[code lang="php"]
$base_url = "http://www.google.com/search";
$ch = curl_init();

for($i=0; $i<20; $i++) {
$url = $base_url . "?q=$i";
curl_setopt($ch, CURLOPT_URL, $url);
curl_exec($ch);
}

curl_close($ch);
?>
[/code]

Octal Notation in Regex

I recently needed to replace the non-standard extended characters that ms-word uses for quotes in over 80 pages. The octal notation available in regular expressions proved to be very helpful. To use octal in a regular expression just escape the three number code like \200.
[code lang="php"]
#!/usr/bin/php -q
for($id = 1; $id<82; $id++) {
$text=mysql_result($result,0,"content");
$new_text = ereg_replace("â\200\234","\"",$text);
$text = $new_text;
$new_text = ereg_replace("â\200\235","\"",$text);
$text = $new_text;
$new_text = ereg_replace("â\200\223","-",$text);
$text = $new_text;
$new_text = ereg_replace("â\200\231","'",$text);
$text = $new_text;
$new_text = ereg_replace("â\200\230","'",$text);
$text = $new_text;
$new_text = ereg_replace("â\200","",$text);
$text = $new_text;
$new_text = ereg_replace("â","\"",$text);
$text = $new_text;
$new_text = ereg_replace("\r\n","\n",$text);
$escaped_text = mysql_escape_string($text);
}
?>
[/code]


There is a fine line between a generic flexible UI and a crappy one:

Got the Chocolate Raspberry Stout in the fermenter. I can't wait to taste it.

Just poured out 10 Liters of overly-carbonated, accidentally-alcoholic, plastic-flavored, homemade root beer. Lessons learned: 3!

Follow me on Twitter