Showing posts with label programming language. Show all posts
Showing posts with label programming language. Show all posts

Thursday, July 14, 2011

in_array strange behavior

use in_array in php?
better check this out because I had mess my script because this strange behavior.
http://www.php.net/manual/en/function.in-array.php#102681

Sunday, February 20, 2011

3 method to open url from php

Method 1:  Curl
//Check for curl before doing anything
if(function_exists(“curl_init”)){
//Initialize curl
$curl_feed = curl_init(“http://netw0rk.blogspot.com/”);
//Curl Options
curl_setopt($curl_feed, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_feed, CURLOPT_HEADER, 0);
//Store our data
$data = curl_exec($curl_feed);
//Close curl
curl_close($curl_feed);
}
Method 2:  fopen
//Initialize fopen
$fopen_feed = @fopen(“http://netw0rk.blogspot.com/”, “r”);
//Make sure fopen was successfull
if ($fopen_feed) {
//Store our data
$data = “”;
while (!feof($fopen_feed)) {
$data .= fread($fopen_feed, 8192);
}
}
//Close fopen
fclose($fopen_feed);
Method 3:  fsockopen
//Initialize fsockopen
$fsockopen_feed = @fsockopen(“http://netw0rk.blogspot.com/”, 80, $errno, $errstr, 30);
if ($fsockopen_feed){
//Create our headers for the request
$headers = “GET http://netw0rk.blogspot.com/  HTTP/1.1\r\n”;
$headers .= “Host:  netw0rk.blogspot.com”\r\n”;
$headers .= “Connection: Close\r\n\r\n”;
fwrite($fsockopen_feed, $headers);
//Store our data
$data = “”;
while (!feof($fsockopen_feed)){
$data .= fgets($fp, 128);
}
//Close fsockopen
fclose($fsockopen_feed);
// Strip the header information
$data = explode(“\\r\\”, $data);
$data = $data[1];
}

Thursday, February 21, 2008

Ruby example, taken from http://www.ruby-lang.org/en/

# Ruby knows what you
# mean, even if you
# want to do math on
# an entire Array
cities = %w[ London
Oslo
Paris
Amsterdam
Berlin ]
visited = %w[Berlin Oslo]

puts "I still need " +
"to visit the " +
"following cities:",
cities - visited