我需要PHP wordwrap而不是{file:filename}的CSS。任何帮助都将深表感谢。
这是PHP手册中的一个例子 -
<?php
$text = "A very long woooooooooooord.";
$newtext = wordwrap($text, 8, "\n", true);
echo "$newtext\n";
?>
包含$ filename的Heres类Fileitem,我假设wordwrap应该在这里的某处。
<?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.');
}
}
?>
这是.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>
答案 0 :(得分:1)
您是否尝试使用<br />
代替\n
?
$newtext = wordwrap($text, 8, "<br />", true);
在您的课程中,添加一个变量,并将其命名为filenameWrap
。
然后,在类构造函数中,执行以下操作:
$this->filenameWrap = wordwrap($filename, 8, "<br />", true);
在您的模板文件中,请拨打{file:filenameWrap}
而不是{file:filename}
。