Get the App
SLTechnology News&Howtos  ›  Development  › 

How php replaces a line of content

Shulou Source: shulou.com Published: 2022-06-03 19:48:10 10月12日 Update

This article mainly explains "how to replace a line of content by php". Friends who are interested may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to replace a line of content by php"!

Operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer

How does php replace a line?

Php replaces the contents of the specified line in the file

First kind

Use the file function to read the file, and each line is an array element

$arr = file ($file); $arr [$line] = "hello"; file_put_contents ($file, implode (", $arr))

The second kind

$fp = new\ SplFileObject ('. / test.php', 'ringing'); / / go to the second line. The seek method parameters are counted from 0, and the pointer points to the end of the line after my test, so the third line $fp- > seek (1) is modified; / / the current line content (second line) $line = $fp- > current (); $fp- > write ("hello")

At this point, I believe you have a deeper understanding of "how php replaces a line of content". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Content line file method learning practical deeper element interest function parameter practicality actual point pointer simple operation array more friends version Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB macOS MySQL Shulou Tech Info