Get Content of URL Into String/Variable

October 10, 2006 | PHP

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 ^_*

 

2 comments


Script Repository

October 9, 2006 | Blog News

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 ^_*

No comment


Up And Running Again

October 9, 2006 | Blog News

This site has re-born!

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

No comment


Faster Array Search in PHP

October 9, 2006 | PHP

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.

3 comments


 



Switch to our mobile site