Oleh: dgtola | 10 Desember 2009

Manipulating Strings: Using Line Breaks

How can a line break be used within HTML? That’s easy: with the <br /> HTML element. However, what if there is data with n or rn line breaks? Search and replace comes to mind; however, it is much easier to use a built-in PHP function: nl2br(). This parses a string and converts all line breaks to <br /> elements, as the preceding script shows.

Adding <br /> Elements at Every Line Break (nl2br.php)
  $input = "OnenTwornThree"; 
  echo nl2br($input);

Outputs the HTML:

One<br />
Two<br />

As you can see, the line breaks are still there, but the <br /> elements were added.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s


%d blogger menyukai ini: