mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
191 lines
7.3 KiB
HTML
191 lines
7.3 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<title>Function to extract a sequence of default grapheme clusters from a text buffer, which must be encoded in UTF-8</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.grapheme-extract" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">grapheme_extract</h1>
|
|
<p class="verinfo">(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)</p><p class="refpurpose"><span class="refname">grapheme_extract</span> — <span class="dc-title">Function to extract a sequence of default grapheme clusters from a text buffer, which must be encoded in UTF-8</span></p>
|
|
|
|
</div>
|
|
<div class="refsect1 description" id="refsect1-function.grapheme-extract-description">
|
|
<h3 class="title">说明</h3>
|
|
<p class="para">过程化风格</p>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>grapheme_extract</strong></span>
|
|
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$haystack</code></span>
|
|
, <span class="methodparam"><span class="type">int</span> <code class="parameter">$size</code></span>
|
|
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$extract_type</code></span>
|
|
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$start</code><span class="initializer"> = 0</span></span>
|
|
[, <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$next</code></span>
|
|
]]] ) : <span class="type">string</span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
Function to extract a sequence of default grapheme clusters from a text buffer, which must be encoded in UTF-8.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.grapheme-extract-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">haystack</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
String to search.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">size</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Maximum number items - based on the $extract_type - to return.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">extract_type</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Defines the type of units referred to by the $size parameter:
|
|
</p>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member">GRAPHEME_EXTR_COUNT (default) - $size is the number of default
|
|
grapheme clusters to extract.</li>
|
|
<li class="member">GRAPHEME_EXTR_MAXBYTES - $size is the maximum number of bytes
|
|
returned.</li>
|
|
<li class="member">GRAPHEME_EXTR_MAXCHARS - $size is the maximum number of UTF-8
|
|
characters returned.</li>
|
|
</ul>
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">start</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Starting position in $haystack in bytes - if given, it must be zero or a
|
|
positive value that is less than or equal to the length of $haystack in
|
|
bytes, or a negative value that counts from the end of $haystack.
|
|
If $start does not point to the first byte of a UTF-8
|
|
character, the start position is moved to the next character boundary.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">next</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Reference to a value that will be set to the next starting position.
|
|
When the call returns, this may point to the first byte position past the end of the string.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.grapheme-extract-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
A string starting at offset $start and ending on a default grapheme cluster
|
|
boundary that conforms to the $size and $extract_type specified.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 changelog" id="refsect1-function.grapheme-extract-changelog">
|
|
<h3 class="title">更新日志</h3>
|
|
<table class="doctable informaltable">
|
|
|
|
<thead>
|
|
<tr>
|
|
<th>版本</th>
|
|
<th>说明</th>
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody class="tbody">
|
|
<tr>
|
|
<td>7.1.0</td>
|
|
<td>
|
|
Support for negative <code class="parameter">start</code>s has been added.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.grapheme-extract-examples">
|
|
<h3 class="title">范例</h3>
|
|
<div class="example" id="example-3093">
|
|
<p><strong>Example #1 <span class="function"><strong>grapheme_extract()</strong></span> example</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br /><br />$char_a_ring_nfd </span><span style="color: #007700">= </span><span style="color: #DD0000">"a\xCC\x8A"</span><span style="color: #007700">; </span><span style="color: #FF8000">// 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5) normalization form "D"<br /></span><span style="color: #0000BB">$char_o_diaeresis_nfd </span><span style="color: #007700">= </span><span style="color: #DD0000">"o\xCC\x88"</span><span style="color: #007700">; </span><span style="color: #FF8000">// 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6) normalization form "D"<br /><br /></span><span style="color: #007700">print </span><span style="color: #0000BB">urlencode</span><span style="color: #007700">(</span><span style="color: #0000BB">grapheme_extract</span><span style="color: #007700">( </span><span style="color: #0000BB">$char_a_ring_nfd </span><span style="color: #007700">. </span><span style="color: #0000BB">$char_o_diaeresis_nfd</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">GRAPHEME_EXTR_COUNT</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
<p class="para">以上例程会输出:</p>
|
|
<div class="example-contents screen">
|
|
<div class="cdata"><pre>
|
|
o%CC%88
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.grapheme-extract-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="grapheme_substr.html" class="function" rel="rdfs-seeAlso">grapheme_substr()</a> - Return part of a string</span></li>
|
|
<li class="member">
|
|
<a href="http://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries" class="link external">»
|
|
Unicode Text Segmentation: Grapheme Cluster Boundaries
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
</div></div></div></body></html> |