douqilai4263 2013-01-22 02:00
浏览 37
已采纳

如何从文件名中删除目录字符串[重复]

Possible Duplicate:
How to get file name from full path with PHP?

echo '<td width="11%" class="imagetd">'. ( ( empty ($arrImageFile[$key]) ) ? "&nbsp;" : htmlspecialchars( is_array( $arrImageFile[$key] ) ? implode(",", $arrImageFile[$key]) : $arrImageFile[$key] ) ). '</td>' . PHP_EOL;
echo '<td width="11%" class="videotd">'. ( ( empty ($arrVideoFile[$key]) ) ? "&nbsp;" : htmlspecialchars( is_array( $arrVideoFile[$key] ) ? implode(",", $arrVideoFile[$key]) : $arrVideoFile[$key] ) ). '</td>' . PHP_EOL;
echo '<td width="11%" class="audiotd">'. ( ( empty ($arrAudioFile[$key]) ) ? "&nbsp;" : htmlspecialchars( is_array( $arrAudioFile[$key] ) ? implode(",", $arrAudioFile[$key]) : $arrAudioFile[$key] ) ). '</td>' . PHP_EOL;

In the above code I have 2 table columns which depending if there are content or not display information in the table cells. Now as you can see the three columns are Image, Video and Audio. Now these columns display the relevant file names in their table cells. Below is how they are displayed:

  • All Image Files contain the string ImageFiles/ before the filename, e.g. ImageFiles/Lighthouse.png
  • All Video Files contain the string VideoFiles/ before the filename, e.g. VideoFiles/sample_mpeg.mp4
  • All Audio Files contain the string AudioFiles/ before the filename, e.g. AudioFiles/Music.mp3

As you can see each file contains the directory string before the filename. But what I want to do is that for each column and for each file, remove the relative directory string or in other words remove ImageFiles/, AudioFiles/ and VideoFiles/ from the whole string of each filename as I do not want the user to know the name of the directory. But how can this be done?

  • 写回答

3条回答 默认 最新

  • dousong1926 2013-01-22 02:05
    关注

    PHP has a function for it: basename

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法