Cara menggunakan php manipulate html

File handling is an important part of any web application. You often need to open and process a file for different tasks.

PHP Manipulating Files

PHP has several functions for creating, reading, uploading, and editing files.

Be careful when manipulating files!

When you are manipulating files you must be very careful.

You can do a lot of damage if you do something wrong. Common errors are: editing the wrong file, filling a hard-drive with garbage data, and deleting the content of a file by accident.

PHP readfile[] Function

The readfile[] function reads a file and writes it to the output buffer.

Assume we have a text file called "webdictionary.txt", stored on the server, that looks like this:

AJAX = Asynchronous JavaScript and XML
CSS = Cascading Style Sheets
HTML = Hyper Text Markup Language
PHP = PHP Hypertext Preprocessor
SQL = Structured Query Language
SVG = Scalable Vector Graphics
XML = EXtensible Markup Language

The PHP code to read the file and write it to the output buffer is as follows [the readfile[] function returns the number of bytes read on success]:

The readfile[] function is useful if all you want to do is open up a file and read its contents.

The next chapters will teach you more about file handling.

PHP Exercises

Test Yourself With Exercises

Exercise:

Assume we have a file named "webdict.txt", write the correct syntax to open and read the file content.

Halo teman-teman pada tutorial Cara Mengedit Banyak Data Menggunakan PHP dan JavaScript Part 2 kali ini kita akan membuat proses untuk edit data nya, pada tutorial sebelumnya kita telah membuat database, file koneksi, file css, dan file index nya.

Untuk membuat proses editnya silahkan teman-teman buka kembali text editornya dan silahkan teman-teman simpan script yang yang terdapat dibahah ini dengan nama edit.php

edit.php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

Bài mới nhất

Chủ Đề