Hướng dẫn php wrap string

❮ PHP String Reference

Example

Wrap a string into new lines when it reaches a specific length:

$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"
\n");
?>

Try it Yourself »


Definition and Usage

The wordwrap() function wraps a string into new lines when it reaches a specific length.

Note: This function may leave white spaces at the beginning of a line.


Syntax

wordwrap(string,width,break,cut)

Parameter Values

ParameterDescription
string Required. Specifies the string to break up into lines
width Optional. Specifies the maximum line width. Default is 75
break Optional. Specifies the characters to use as break. Default is "\n"
cut Optional. Specifies whether words longer than the specified width should be wrapped:
  • FALSE - Default. No-wrap
  • TRUE - Wrap


Technical Details

Return Value:Returns the string broken into lines on success, or FALSE on failure.
PHP Version:4.0.2+
Changelog:The cut parameter was added in PHP 4.0.3

More Examples

Example

Using all parameters:

$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"
\n",TRUE);
?>

Try it Yourself »

Example

Wrap a string into new lines:

$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15);
?>

The HTML output of the code above will be (View Source):




An example of a
long word is:
Supercalifragulistic

The browser output of the code above will be:

An example of a long word is: Supercalifragulistic

Try it Yourself »


❮ PHP String Reference


this is my first questions in stack overflow. i want build search result in php. i have code like below:

".$kw."", $title)."
"; } ?>

but why i cant get the result with it?

thank you

asked Dec 18, 2020 at 7:08

Hướng dẫn php wrap string

4

  • If you can include the result you are getting and the result you are after, it would help understand where the problem may be.

    Dec 18, 2020 at 7:10

  • for example i typed "news" in search form. then the result is: 1. Latest News about Covid 2. World News Today 3. The Best News This Months i want wrap the "news" string with in html tag use str_replace but the result give the plain text only, without wrapped with html tag inside

    Dec 18, 2020 at 7:14

  • If you type in News - does that work. It sounds like a problem with being case sensitive.

    Dec 18, 2020 at 7:24

  • oh i see, you are answer right !!! thank you dude. i just realize that function str_replace() is case sensitive, now i use str_ireplace() and work like charm... php.net/manual/en/function.str-ireplace.php

    Dec 18, 2020 at 7:51

Hướng dẫn dùng tanh trong PHP

Bài này sẽ giới thiệu cú pháp (syntax) và các thành phần cơ bản trong PHP. Để học tốt bài này, các bạn cần đọc lại bài Cài đặt môi trường lập trình ...

Hướng dẫn dùng carbon format trong PHP

Sử dụng Carbonb package trong Laravel và PHPCarbon Laravel là một gói phần mềm được phát triển bởi Brian Nesbit mở rộng từ class DateTime của PHP. Từ phiên bản 5.3, ...

Hướng dẫn dùng backward type trong PHP

Trong hướng dẫn này, bạn sẽ tìm hiểu về các kiểu dữ liệu có sẵn trong PHP như Int, String, Float, Number, Double, Boolean, Array, Object…Các kiểu dữ liệu trong ...

Hướng dẫn dùng as list trong PHP

Cú phápHàm list() trong PHP có cú pháp như sau:list ( $var1, $var2, $var3.. ) Định nghĩa và cách sử dụngGiống hàm array(), hàm này không thực sự là một hàm. Hàm list() ...

Hướng dẫn dùng inside crypt trong PHP

❮ Tham chiếu chuỗi PHPĐịnh nghĩa và Cách sử dụngHàm crypt () trả về một chuỗi được băm bằng cách sử dụng các thuật toán DES, Blowfish hoặc MD5.Chức năng ...

Hướng dẫn dùng string. trong PHP

1) Chuỗi là gì !?- Chuỗi (hay còn gọi được là chuỗi ký tự) là một dãy các ký tự.- Ví dụ: Tai Chuỗi gồm 3 ký tự Tai lieu Chuỗi gồm 8 ký tự Tai lieu ...

Hướng dẫn dùng md5 encrypter trong PHP

1. Chức năng của hàm md5()Hàm md5() trong PHP có chức năng mã hóa một chuỗi ký tự thành một chuỗi ký tự khác gồm có 32 ký tự với hàm băm (hash) mật mã học ...

Hướng dẫn php run command

PHP CLI (Command Line Interface) hay giao diện dòng lệnh PHP là chương trình dịch PHP độc lập hoạt động ở chế độ dòng lệnh tương tự như chương trình dịch ...

Hướng dẫn dùng find parent trong PHP

Hàm get_parent_class() trong PHP có nhiệm vụ lấy ra tên class Parent của một đối tượng hoặc một Class.Nội dung chínhTham số truyền vào Giá trị trả về Ví ...

Hướng dẫn dùng data hash trong PHP

Tìm hiểu khi sử dụng các hàm băm tạo dữ liệu lưu trữ passwordKhi lưu trữ password vào CSDL thường sẽ sử dụng các hàm băm khác nhau được hỗ trợ bởi hệ ...

Hướng dẫn dùng yaml parser trong PHP

Spyc: https://github.com/mustangostang/spycNội dung chính2. YML YAML là gì?2. YML khác YAML chỗ nào?3. Tại sao chọn YML?II. Parse YML YAML như nào?1. YML YAML là gì? YML và YAML là ...

Hướng dẫn dùng calculate gcd trong PHP

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)gmp_gcd — Calculate GCDDescriptiongmp_gcd(GMP|int|string $num1, GMP|int|string $num2): GMPParameters num1A GMP object, an int or a numeric string. num2A GMP ...

Hướng dẫn dùng indexed list trong PHP

Phần này trình bày cách sử dụng elasticsearch-php là thư viện để PHP kết nối làm việc với Elasticsearch.Nội dung chínhCấu hình kết nối PHP tới ElasticsearchTạo ...

Hướng dẫn dùng normalizr trong PHP

normalizer_normalize(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)Normalizer::normalize -- normalizer_normalize — Normalizes the input provided and returns the normalized string ...

Hướng dẫn php-fpm là gì

PHP-FPM cho phép tăng tốc PHP lên gấp nhiều lần, đặc biệt phù hợp với các web server có lưu lượng truy cập lớn. Bài viết này sẽ đi sâu vào giải thích về ...

Hướng dẫn dùng dont br trong PHP

Thao tác với chuỗi (String) trong PHP là một kỹ năng cực kỳ quan trọng khi lập trình web với PHP. Hôm nay mình sẽ hướng dẫn bạn cách sử dụng 12 hàm thao tác ...

Hướng dẫn php security github

Web Application SecurityIntroductionThis document will list possible security threats to the Web application, explanation and preventive measures.FootprintingScanningSQL injectionFile UploadSession ...

Hướng dẫn dùng namespace trong PHP

Trong một dự án lớn có bao giờ bạn nghĩ đến trường hợp là sẽ xảy ra các class có trùng tên nhau không? Chính vì điều đó mà kể tử phiên bản PHP 5.3 trở ...

Hướng dẫn dùng php map trong PHP

Hàm array_map() sẽ lặp tất cả các phần tử của mảng và truyền vào hàm callback định nghĩa trước đó của người dùng. Hàm callback sẽ coi các phần từ của ...

Hướng dẫn dùng modidy trong PHP

Hàm date_modify() sẽ thay đổi mốc thời gian của đối tượng thời gian. Cụ thể, hàm sẽ thêm bớt một khoảng thời gian nào đó vào một mốc thời gian.Bài ...