PHP: converting fopen to file_get_contents?

494 views Asked by At

I'm experimenting around which is faster and more efficient so I found my old scipt using fopen. How can I convert this to file_get_contents?

PHP:

class.......
$filename = 'test.txt';
$this->filepointer = fopen($filename, 'rb');
$length = filesize($filename);

public function read_name($length)
{
$name = fread($this->filepointer, $length);
return str_replace("\0", '', $name);
}
.....

can someone guide me how to convert it to file_get_contents?

1

There are 1 answers

0
kaldoran On

Answer :

$name = file_get_contents($filename);
return str_replace("\0", '', $name);