Home >Backend Development >PHP Tutorial >PHP code that reads file content into a string and processes it

PHP code that reads file content into a string and processes it

WBOY
WBOYOriginal
2016-07-25 09:04:421219browse
  1. /*

  2. *Read the file content into a string, while removing newlines and spaces at the beginning and end of the line.
  3. */
  4. header("Content-type: text/html; charset=utf-8");
  5. echo preg_replace('/((s)*(n)+(s)*)/i',',' ,file_get_contents('./file.php'));//End_php

  6. //Output:

  7. //aaaa,bbbb,cccc,dddd,eeee,ffff,gggg,hhhh,iiii, jjjj,kk kk,ll ll
  8. ?>

Copy code

file.php content: aaaa

cccc dddd eeee ffff ggg hhhh iiii jjjj kkkk ll ll

//file.php replace space (x), Tab (T) effect aaaa

TTTT cccc ddddT xxxxxxxxxxxT eeeexxxxxxxxxx ffff ggg hhhhxxxxxxxxx xxxxxxxxxiii xxxxxxxxjjjjxxxxxxx kkxxxkkTT xxxxllxxllTT Txxxxxxxxxx TTTxx



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn