Php 在不带url的while循环中显示文件名
我只想显示文件名而不显示url。 我想替换文件名而不是“文档”Php 在不带url的while循环中显示文件名,php,Php,我只想显示文件名而不显示url。 我想替换文件名而不是“文档” while($fet=mysql_fetch_assoc($sql1)) { $i=$i+1; $next=$fet['f_name']; echo '<h4><a class="astext" href="'.$next.'" title="'.$next.'" target="_blank" downloa
while($fet=mysql_fetch_assoc($sql1))
{
$i=$i+1;
$next=$fet['f_name'];
echo '<h4><a class="astext" href="'.$next.'" title="'.$next.'" target="_blank" download>Document'.$i.'</a></h4>';
}
while($fet=mysql\u fetch\u assoc($sql1))
{
$i=$i+1;
$next=$fet['f_name'];
回声';
}
如果我将单词“document”替换为$next,它将显示完整的url,因为我需要显示sample.doc
echo '<h4><a class="astext" href="'.$next.'" title="'.$next.'" target="_blank" download>"'.$next.'"</a></h4>';
echo';
有两种选择
假设您有$next=http://www.sample/txt/1/sample.doc
选项1:
如果您认为http://www.sample/txt/1/
适用于所有文件夹
ltrim($next,“”)
选项2:
使用basename($next)
这将提取样本。doc有两个选项
<?php
$link = "http://www.sample/txt/1/sample.doc";
$linkArray = explode('/', $link);
echo $linkArray[count($linkArray)-1];
?>
假设您有$next=http://www.sample/txt/1/sample.doc
选项1:
如果您认为http://www.sample/txt/1/
适用于所有文件夹
ltrim($next,“”)
选项2:
使用basename($next)
这将提取sample.doc
<?php
$link = "http://www.sample/txt/1/sample.doc";
$linkArray = explode('/', $link);
echo $linkArray[count($linkArray)-1];
?>
马格什库马尔也提供了良好的
<?php
$link = "http://www.sample/txt/1/sample.doc";
echo basename($link);
?>
马格什库马尔也提供了良好的
<?php
$link = "http://www.sample/txt/1/sample.doc";
echo basename($link);
?>
我包括$next1=basename($next)
while($fet=mysql\u fetch\u assoc($sql1))
{
$i=$i+1;
$next=$fet['f_name'];
$next1=basename($next);
回声';
}
它现在可以工作了。我包括$next1=basename($next)
<?php
$url = "http://www.sample/txt/1/sample.doc";
echo strstr($url,"sample.");
while($fet=mysql\u fetch\u assoc($sql1))
{
$i=$i+1;
$next=$fet['f_name'];
$next1=basename($next);
回声';
}
现在可以工作了。
<?php
$url = "http://www.sample/txt/1/sample.doc";
echo strstr($url,"sample.");
仅供参考:)编辑选项中有一个选项回答您自己的问题
。仅供参考:)编辑选项中有一个选项回答您自己的问题
。选项2适用于我的问题。出于某种原因,我动态创建了文件夹。感谢选项2适合我的问题。出于某种原因,我动态创建了文件夹。谢谢