问题描述:

This question already has an answer here:

  • Best Practices: working with long, multiline strings in PHP?

    7 answers

网友答案:

How about this, which allows you to use unescaped quote marks in your text block:

$str = <<<DATA
saldflasdfl

asdklksadlasd "quoted string"


aslkdlsadfkl
DATA;

Note that it does need to be added with no whitespace indentation, since that would be taken to be part of the string.

However, do note that if your text block gets over a certain size, it is probably cleaner to put it in a text file and read it into a string.

网友答案:

You need to escape ":

$str = "saldflasdfl

asdklksadlasd \"quoted string\"


aslkdlsadfkl";
网友答案:

This code reads the whole file.

$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
$str =  fread($myfile,filesize("webdictionary.txt"));
fclose($myfile);

If you wanna read one line at a time you can do this:

$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
// Output one line until end-of-file
while(!feof($myfile)) {
  echo fgets($myfile) . "<br>";
}
fclose($myfile);

Source: http://www.w3schools.com/php/php_file_open.asp

相关阅读:
Top