[英]How can I add PHP wordwrap to this class?
I need to do PHP wordwrap not CSS of {file:filename}. 我需要做PHP换行而不是{file:filename}的CSS。 Any help would be sincerely appreciated. 任何帮助将由衷的感谢。
Here's an example from the PHP Manual - 这是PHP手册中的示例-
<?php
$text = "A very long woooooooooooord.";
$newtext = wordwrap($text, 8, "\n", true);
echo "$newtext\n";
?>
Heres class Fileitem that contains $filename, I'm assuming the wordwrap should go somewhere in here. 这里的类Fileitem包含$ filename,我假设自动换行应该放在这里的某个地方。
<?php
class FileItem extends Item
{
/**
* @param string $fn The filename
* @return string Everything after the list dot in the filename, not including the dot
*/
public static function ext($fn)
{
$fn = Item::get_basename($fn);
return (strpos($fn, '.') ? strtolower(substr(strrchr($fn, '.'), 1)) : '');
}
/**
* @return string Returns the extension of the filename
* @see FileItem::ext()
*/
public function file_ext()
{
return self::ext($this -> filename);
}
/**
* @param string $parent_dir
* @param string $filename
*/
public function __construct($parent_dir, $filename)
{
parent::__construct($parent_dir, $filename);
if (!@is_file($this -> parent_dir . $filename))
{
throw new ExceptionDisplay('File <em>'
. Url::html_output($this -> parent_dir . $filename)
. '</em> does not exist.');
}
global $config, $words, $downloads;
$this -> filename = $filename;
$this -> size = new Size(filesize($this -> parent_dir . $filename));
if (ICON_PATH)
{
$file_icon = new Icon($filename);
$this -> icon = $file_icon -> __toString();
}
$this -> downloads = (DOWNLOAD_COUNT && $downloads -> is_set($parent_dir . $filename) ? (int)($downloads -> __get($parent_dir . $filename)) : 0);
$this -> link = Url::html_output($_SERVER['PHP_SELF']) . '?dir=' . Url::translate_uri(substr($this -> parent_dir, strlen($config -> __get('base_dir'))))
. '&file=' . Url::translate_uri($filename);
if (THUMBNAIL_HEIGHT && in_array(self::ext($filename), array('png', 'jpg', 'jpeg', 'gif')))
{
$this -> thumb_link = ' <img src="' . Url::html_output($_SERVER['PHP_SELF'])
. '?thumbnail='. Url::translate_uri($this -> parent_dir . $filename)
. '" alt="' . $words -> __get('thumbnail of') . ' ' . $filename
. '" />';
}
$size = $this -> size -> __get('bytes');
if (MD5_SHOW && $size > 0 && $size / 1048576 <= $config -> __get('md5_show'))
{
$this -> md5_link = '<span class="autoindex_small">[<a class="autoindex_a" href="'
. Url::html_output($_SERVER['PHP_SELF']) . '?dir='
. Url::translate_uri(substr($this -> parent_dir, strlen($config -> __get('base_dir'))))
. '&md5=' . Url::translate_uri($filename) . '">'
. $words -> __get('calculate md5sum') . '</a>]</span>';
}
}
/**
* @param string $var The key to look for
* @return mixed The data stored at the key
*/
public function __get($var)
{
if (isset($this -> $var))
{
return $this -> $var;
}
throw new ExceptionDisplay('Variable <em>' . Url::html_output($var)
. '</em> not set in FileItem class.');
}
}
?>
This is where filename outputs in a .tpl file 这是.tpl文件中文件名输出的位置
<tr class="{file:tr_class}">
<td class="auto_td">
<p class="Column1"><a class="auto_a" href="{file:link}">
{if:icon_path}<img width="16" height="16" alt="[{file:file_ext}]" src="{file:icon}" />{end if:icon_path}
{file:filename} {file:thumbnail}
</a>{file:new_icon}{file:md5_link}{file:delete_link}{file:rename_link}{file:edit_description_link}{file:ftp_upload_link}
</p>
</td>
<td class="autoindex_td_right">
<div class="Column2">
{file:size}
</div>
</td>
{if:description_file}
<td class="description">
<p class="Column3">
{file:description}
</p>
</td>
{end if:description_file}
<td class="download">
<p class="Column4">
<a href="{file:link}" class="dlButton">Download</a>
</p>
</td>
</tr>
Did you try with <br />
instead of \\n
? 您是否尝试使用<br />
而不是\\n
?
$newtext = wordwrap($text, 8, "<br />", true);
In your class, add a variable and name it filenameWrap
for example. 在您的类中,添加一个变量并将其命名为filenameWrap
。
Then, in your class constructor, do this: 然后,在您的类构造函数中,执行以下操作:
$this->filenameWrap = wordwrap($filename, 8, "<br />", true);
And in your template file, call {file:filenameWrap}
instead of {file:filename}
. 然后在模板文件中,调用{file:filenameWrap}
而不是{file:filename}
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.