Load File into a String

Simple old function to load a file into a string.

Novembre 9, 2009

Simple old function to load a file into a string.


$s = loadStrFile("file.txt");

function loadStrFile($filename) {
	$handle = fopen ($filename, "rb");
	$contents = fread ($handle, filesize ($filename));
	fclose ($handle);
	return $contents;
}

Author

PHP expert. Wordpress plugin and theme developer. Father, Maker, Arduino and ESP8266 enthusiast.

Comments on “Load File into a String”

One thought

  1. seeal ha detto:

    Really nice blog, nice snippet codes, thx 4 sharing :D

Comments are closed

Recommended

The Quantcast CMP broke my sites

A javascript error in CMP blocks my site.

Maggio 19, 2023

WP Gutenberg notes

Collection of notes and thoughts on Wordpress Gutenberg blocks development.

Gennaio 9, 2023

Optimizing LCP, Largest Contentful Paint result

Notes about Core Web Vitals optimization challenge

Gennaio 4, 2023

Find values recursively inside complex json objects in PHP

A PHP function to to quickly search complex, nested php structures for specific values.

Dicembre 18, 2022

Scroll to DIV by ID without jQuery

Use scrollIntoView instead of jQuery animate.

Dicembre 16, 2022