本文整理汇总了PHP中Cake\Utility\Text::wrap方法的典型用法代码示例。如果您正苦于以下问题:PHP Text::wrap方法的具体用法?PHP Text::wrap怎么用?PHP Text::wrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Utility\Text
的用法示例。
在下文中一共展示了Text::wrap方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeTextOnImage
public function writeTextOnImage($fontSize, $fontFile, $fontColor, $text, &$img, $positionX, $positionY)
{
if (!$text) {
return false;
}
$text = preg_replace('/[?]+/', "", $text);
$text = \Cake\Utility\Text::wrap($text, 40);
$text = \Cake\Utility\Text::truncate($text, 80, ['exact' => false]);
$fontColor = $this->hex2rgb($fontColor);
$color = imagecolorallocate($img, $fontColor[0], $fontColor[1], $fontColor[2]);
$result = imagettftext($img, $fontSize, 0, $positionX, $positionY, $color, $fontFile, trim($text));
}
示例2: wrapText
/**
* Wrap a block of text.
* Allows you to set the width, and indenting on a block of text.
*
* ### Options
*
* - `width` The width to wrap to. Defaults to 72
* - `wordWrap` Only wrap on words breaks (spaces) Defaults to true.
* - `indent` Indent the text with the string provided. Defaults to null.
*
* @param string $text Text the text to format.
* @param int|array $options Array of options to use, or an integer to wrap the text to.
* @return string Wrapped / indented text
* @see \Cake\Utility\Text::wrap()
* @link http://book.cakephp.org/3.0/en/console-and-shells.html#Shell::wrapText
*/
public function wrapText($text, $options = [])
{
return Text::wrap($text, $options);
}
示例3: text
/**
* Get the help as formatted text suitable for output on the command line.
*
* @param int $width The width of the help output.
* @return string
*/
public function text($width = 72)
{
$parser = $this->_parser;
$out = [];
$description = $parser->description();
if (!empty($description)) {
$out[] = Text::wrap($description, $width);
$out[] = '';
}
$out[] = '<info>Usage:</info>';
$out[] = $this->_generateUsage();
$out[] = '';
$subcommands = $parser->subcommands();
if (!empty($subcommands)) {
$out[] = '<info>Subcommands:</info>';
$out[] = '';
$max = $this->_getMaxLength($subcommands) + 2;
foreach ($subcommands as $command) {
$out[] = Text::wrapBlock($command->help($max), ['width' => $width, 'indent' => str_repeat(' ', $max), 'indentAt' => 1]);
}
$out[] = '';
$out[] = sprintf('To see help on a subcommand use <info>`cake %s [subcommand] --help`</info>', $parser->command());
$out[] = '';
}
$options = $parser->options();
if (!empty($options)) {
$max = $this->_getMaxLength($options) + 8;
$out[] = '<info>Options:</info>';
$out[] = '';
foreach ($options as $option) {
$out[] = Text::wrapBlock($option->help($max), ['width' => $width, 'indent' => str_repeat(' ', $max), 'indentAt' => 1]);
}
$out[] = '';
}
$arguments = $parser->arguments();
if (!empty($arguments)) {
$max = $this->_getMaxLength($arguments) + 2;
$out[] = '<info>Arguments:</info>';
$out[] = '';
foreach ($arguments as $argument) {
$out[] = Text::wrapBlock($argument->help($max), ['width' => $width, 'indent' => str_repeat(' ', $max), 'indentAt' => 1]);
}
$out[] = '';
}
$epilog = $parser->epilog();
if (!empty($epilog)) {
$out[] = Text::wrap($epilog, $width);
$out[] = '';
}
return implode("\n", $out);
}
示例4: testWrapBlockIndenticalToWrap
/**
* test wrapBlock() indentical to wrap()
*
* @return void
*/
public function testWrapBlockIndenticalToWrap()
{
$text = 'This is the song that never ends. This is the song that never ends. This is the song that never ends.';
$result = Text::wrapBlock($text, 33);
$expected = Text::wrap($text, 33);
$this->assertTextEquals($expected, $result);
$result = Text::wrapBlock($text, ['width' => 33, 'indentAt' => 0]);
$expected = Text::wrap($text, ['width' => 33, 'indentAt' => 0]);
$this->assertTextEquals($expected, $result);
}
示例5: testWrapIndent
/**
* test wrap() indenting
*
* @return void
*/
public function testWrapIndent()
{
$text = 'This is the song that never ends. This is the song that never ends. This is the song that never ends.';
$result = Text::wrap($text, ['width' => 33, 'indent' => "\t", 'indentAt' => 1]);
$expected = <<<TEXT
This is the song that never ends.
\tThis is the song that never ends.
\tThis is the song that never ends.
TEXT;
$this->assertTextEquals($expected, $result);
}