Archive for October, 2006

Get Content of URL Into String/Variable

Tuesday, October 10th, 2006

Here is a simple code to get a content of URL (HTML file) and put it into a variable/string. This is useful for content grabbing, for example.

function getContentOfURL($url){
$file = fopen($url, "r");
if($file){
while (!feof ($file)) {
$line .= fread ($file, 1024*50);
}
return $line;
}
}
?>

Usage:
$string = getContentOfURL("http://sitename.com/index.htm");
?>

yeah, as easy as that ^_*

 

Script Repository

Monday, October 9th, 2006

Beside writing code and description here in this blog, I also posted the script in a directory. You can easily view my scripts at my scripts repository.

You can see if my repository is updated by looking at the right panel after the “Previous Post” section. Hope it will help many people ^_*

Up And Running Again

Monday, October 9th, 2006

This site has re-born!

Yeah, it was dropped out. The server was hacked, said the customer service. Yeah, sad but true…

Faster Array Search in PHP

Monday, October 9th, 2006

I used to use in_array() function to find if a string exist in an array. But then I find out that there’s a faster method to do this using isset().

First method, using in_array() function:

$nama = array("yuna","sakura","miyabi","sena");
if(in_array("yuna",$name)) echo "we have yuna here!";
?>

and seem it’s too slow. PHP will loop the array and check one by one to see if we have yuna in the array.

Then using isset() function as follow:

$nama = array("yuna","sakura","miyabi","sena");
if(isset($name['yuna'])) echo "we have yuna here!";
?>

it will just check if yuna is exist, no loop, no pain.