You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+54-3Lines changed: 54 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,22 @@ Cochrane, this library has been improved and made more complete by Nick Pope.
17
17
</a>
18
18
</p>
19
19
20
+
## Requirements ##
21
+
22
+
- PHP 5.3 or higher
23
+
- ext-mbstring
24
+
- ext-intl
25
+
26
+
If the necessary extensions are not installed on the server, please install it additionally or use [symfony/polyfill](https://github.com/symfony/polyfill).
27
+
28
+
## Install ##
29
+
30
+
You can install this library into your application using [Composer](https://getcomposer.org/).
31
+
32
+
```
33
+
composer require nojimage/twitter-text-php
34
+
```
35
+
20
36
## Features ##
21
37
22
38
### Autolink ##
@@ -47,6 +63,43 @@ Cochrane, this library has been improved and made more complete by Nick Pope.
47
63
- Validate different twitter text elements.
48
64
- Support for international character sets.
49
65
66
+
### Parser ###
67
+
68
+
- Parses a given tweet text with the weighted character count configuration.
69
+
70
+
## Length validation ##
71
+
72
+
twitter-text 2.0 introduces configuration files that define how Tweets are parsed for length. This allows for backwards compatibility and flexibility going forward. Old-style traditional 140-character parsing is defined by the v1.json configuration file, whereas v2.json is updated for "weighted" Tweets where ranges of Unicode code points can have independent weights aside from the default weight. The sum of all code points, each weighted appropriately, should not exceed the max weighted length.
73
+
74
+
Some old methods from twitter-text-php 1.0 have been marked deprecated, such as the `Twitter\Text\Validator::isValidTweetText()`, `Twitter\Text\Validator::getTweetLength()` method. The new API is based on the following method, `Twitter\Text\Parser::parseTweet()`
This method takes a string as input and returns a results object that contains information about the string. `Twitter\Text\ParseResults` object includes:
81
+
82
+
-`weightedLength`: the overall length of the tweet with code points
83
+
weighted per the ranges defined in the configuration file.
84
+
85
+
-`permillage`: indicates the proportion (per thousand) of the weighted
86
+
length in comparison to the max weighted length. A value > 1000
87
+
indicates input text that is longer than the allowable maximum.
88
+
89
+
-`valid`: indicates if input text length corresponds to a valid
90
+
result.
91
+
92
+
-`displayRangeStart, displayRangeEnd`: An array of two unicode code point
93
+
indices identifying the inclusive start and exclusive end of the
94
+
displayable content of the Tweet. For more information, see
0 commit comments