Hướng dẫn dùng wordcounter.net trong PHP

What is WordCounter?

Apart from counting words and characters, our online editor can help you to improve word choice and writing style, and, optionally, help you to detect grammar mistakes and plagiarism. To check word count, simply place your cursor into the text box above and start typing. You'll see the number of characters and words increase or decrease as you type, delete, and edit them. You can also copy and paste text from another program over into the online editor above. The Auto-Save feature will make sure you won't lose any changes while editing, even if you leave the site and come back later. Tip: Bookmark this page now.

Knowing the word count of a text can be important. For example, if an author has to write a minimum or maximum amount of words for an article, essay, report, story, book, paper, you name it. WordCounter will help to make sure its word count reaches a specific requirement or stays within a certain limit.

In addition, WordCounter shows you the top 10 keywords and keyword density of the article you're writing. This allows you to know which keywords you use how often and at what percentages. This can prevent you from over-using certain words or word combinations and check for best distribution of keywords in your writing.

In the Details overview you can see the average speaking and reading time for your text, while Reading Level is an indicator of the education level a person would need in order to understand the words you’re using.

Disclaimer: We strive to make our tools as accurate as possible but we cannot guarantee it will always be so.

There may be certain times when instead of wanting to know the word count of your own writing, you'd like to know a website's word count. That is, you'd like to know the word count for a website without having to actually count all the words on the page by hand. Website Word Count is a tool which will do exactly that for you. It's a website word counter created specifically so you can find out the number of words on any page on the Internet. All you need to know is the URL of a web page, place it into the tool, and you can find out exactly how many words are on that page by hitting the "count" button. The tool will count the words on the website's page and instantly provide that number to you.

Even better, this website word counter will also provide you with a list of the keywords used on the page you request. Not only will you know how many word are written on the page, you'll also know the most common words used on the page. The keyword density list is broken down into two parts. On the left, the tool displays a list of the most common words used on the page entered. The list on the right documents the keyword density of the page excluding all commonly used words [this gives a better indication of what the main topic of the page happens to be, and the keywords used for that topic].

There are a number of ways this information might be valuable. Translators often want to know the number of words on a web page because it's common for them to charge clients by the number of words on the page they are translating, and not necessarily the number of words they write in the translated language or by the time they spend on it. For this reason, being able to quickly determine the word count of a page is important.

A reader may simply be curious to know how many words are on the pages of certain writers or bloggers they follow. A writer may also covet this information if they want to style their writing after another blogger or writer they admire. This information may be able to help them better build a website or blog they desire.

This tool can also be used to check the pages of your own website or blog. When you know which pages are the most popular on your own site, you can enter their URLs to see what number of words seems to perform best with the topics you write about. This can help you write content in the future that also brings more readers to see your writing.

It can also be of great help for those who write articles for websites and bloggers. For example, for those interested in SEO, they will be able to see the word count and keyword density for popular pages on the Internet on any topic about which they may be writing. This information can give them hints on how to better rank their own writing on that particular topic.

No matter the reason you decide to use this counter, it should provide you with valuable information you can use to better your writing in addition to the overall content for the blogs and websites for which you write. We are always looking to improve the counters we provide. If you have suggestions you feel would make this tool better, please use the "contact us" link at the top of this page to give us your suggestions.

Ví dụ dưới dây hướng dẫn bạn các cách Convert Strong to Array trong PHP đơn giản

Nội dung chính

  • Cách 1 - Convert String to Array bằng SPLIT 
  • Cách 2 - Convert String to Array bằng EXPLODE 
  • Cách 3 - Convert String to Array bằng PREG SPLIT
  • Cách 4 - Convert String to Array bằng STRING WORD COUNT
  • Cách 5 - Convert String to Array bằng For Loop
  • Hàm Implode [] trong PHP:
  • Hàm Join [] trong PHP
  • Hàm Json_encode [] trong PHP

Cách 1 - Convert String to Array bằng SPLIT 

// [A] cho một chuỗi  
$thestring = "FOOBAR";
 
// [B] Cắt các ký tự thành phẩn tử của array
$thearray = str_split[$thestring];
print_r[$thearray]; // F, O, O, B, A, R
 
// [C] Set số ký tự tạo thành array
$thearray = str_split[$thestring, 3];
print_r[$thearray]; // FOO, BAR

Cách 2 - Convert String to Array bằng EXPLODE 

// [A] THE STRING
$thestring = "FOO-BAR";
 
// [B] Convert thành array bằng 1 ký tự '-'
$thearray = explode["-", $thestring];
print_r[$thearray]; // FOO, BAR

Cách 3 - Convert String to Array bằng PREG SPLIT

// [A] THE STRING
$thestring = "FOO BAR, HELLO WORLD";
 
// [B] SPLIT BY PATTERN
$thearray = preg_split["/[\s|,\s]/", $thestring];
print_r[$thearray]; // ["FOO", "BAR", "HELLO", "WORLD"]

Trên ví dụ trên ta dùng preg_split[] function , điểm đặc biệt là function này dùng 1 tham số để cắt chuỗi thành array là một regular expression [ ở đây là  /[\s|,\s]/ ].

Regular expression còn gọi là Regex là những kỹ thuật viết biểu thức để tìm kiếm chuỗi trùng phù hợp

Cách sử dụng này khá mạnh mẽ bởi có sự xuất hiện của Regex, tuy nhiên nó hơi khó với người chưa biết về Regex.

Cách 4 - Convert String to Array bằng STRING WORD COUNT

// [A] THE STRING
$thestring = "Foo Bar, hello world. Goodbye world3 = [email protected]";
 
// [B] STR_WORD_COUNT[STRING, FORMAT, LIST]
// [B1] FORMAT là 0 - Trả số lượng từ hợp lệ
echo str_word_count[$thestring, 0]; // 8
 
// [B2] FORMAT là 1 - Trả về các từ hợp lệ 
$thearray = str_word_count[$thestring, 1];
print_r[$thearray]; // Foo, Bar, hello, world, Goodbye, world, John, Doe
 
// [B3] FORMAT là  2 - Trả về các từ có giá trị kèm vị trí bắt đầu của ký tự đó.
$thearray = str_word_count[$thestring, 2];
print_r[$thearray]; 
/* 0 - Foo,
 * 4 - Bar,
 * 9 - hello,
 * 15 - world,
 * 22 - Goodbye,
 * 30 - world,
 * 39 - John,
 * 44 - Doe
 */

// [C] LIST - Các ký tự được xác đinh là tiếng anh
$thearray = str_word_count[$thestring, 2, "[email protected]"];
print_r[$thearray]; 
/* 0 - Foo,
 * 4 - Bar,
 * 9 - hello,
 * 15 - world,
 * 22 - Goodbye,
 * 30 - world3,
 * 39 - [email protected]
 */

str_word_count [] có thể không phải là một hàm được sử dụng để chuyển đổi một chuỗi thành một mảng, nhưng nó vẫn có thể làm được điều này.

Hơi khó hiểu, nhưng str_word_count [STRING, MODE, LIST] có 3 tham số.

+ Tham số đầu tiên là chính STRING.

+ Tham số thứ hai là tham số quan trọng "thay đổi" CHẾ ĐỘ của hàm.

  • 0 sẽ chỉ đơn giản là đếm tổng số từ tiếng Anh hợp lệ trong chuỗi. Không phải những gì chúng tôi đang tìm kiếm.
  • 1 sẽ trả về một mảng các từ hợp lệ trong chuỗi - Có, điều này rất hữu ích nếu bạn muốn lọc ra tất cả các từ vô nghĩa trong một chuỗi.
  • 2 làm tương tự như 1. Nhưng chỉ số của mảng sẽ tương ứng với vị trí bắt đầu của từ trong chuỗi.

+ Cuối cùng, tham số LIST cuối cùng là tùy chọn - Chúng ta có thể sử dụng tham số này để ghi đè và yêu cầu PHP chấp nhận danh sách các ký tự này là “từ tiếng Anh hợp lệ”.

Cách 5 - Convert String to Array bằng For Loop

// [A] THE STRING
$thestring = "FOO-BAR";
 
// [B] MANUAL LOOP & SPLIT
$thearray = [];
for [$i=0; $i implode [separator, array]  

Ở đây dấu phân tách đề cập đến những gì chúng ta phải thêm vào giữa các phần tử của một mảng trong quá trình chuyển đổi nó thành một chuỗi.

Giá trị mặc định là một chuỗi rỗng "", nhưng chúng ta có thể thêm nhiều giá trị khác nhau như "," "-" "_" "+" ";" ":" ...

Ví dụ: Để chuyển một mảng thành chuỗi.

  

Kết quả:

Array [ [0] = > This [1] = > Array [2] = > Will [3] = > Be [4] = > Converted [5] = > To [6] = > A [7] = > String ] 
converted array 
This Array Will Be Converted To A String

Diễn giải:

Đầu tiên, chúng ta đã khai báo một mảng với tên $arra và gán một số giá trị cho nó.

Để hiển thị bản gốc, chúng tôi đã sử dụng hàm Print_r, hàm này hiển thị từng mảng riêng biệt.

Và cuối cùng, chúng ta đã sử dụng hàm implode [] sẽ chuyển đổi tất cả các phần tử của một mảng thành một chuỗi kèm thêm khoảng cách giữa các phần tử và tên mảng để xác định mảng.

Ví dụ: Để chuyển một mảng thành chuỗi với các tham số khác nhau.

Chủ Đề