-1

I'm using the following code to display the name of a CSV file before the contents of the CSV file are displayed on a PHP page. It works well and displays the name of the file as it should:

CODE:

    #$result .= '<h3>'.$prog.'</h3>'.PHP_EOL; // OLD STYLE
    $result .= '<h3>'.$prog. ' '.$_POST['filename'].'</h3>'.PHP_EOL; // NEW STYLE
    $result .= '</div>'.PHP_EOL;
    $result .= $contents.PHP_EOL;

Problem is, I don't want the file name to display the extension (in my code example, it is .csv)

Can anyone assist in the right code needed to remove the extension (.CSV)...?

Sam West
  • 21
  • 1
  • 4

1 Answers1

3

// Use this code I hope it's useful ..
=> The basename() function returns the filename

<?php
$path = "filename.CSV"; // set your file name 

//Show filename with file extension
echo basename($path) ."<br/>";

//Show filename without file extension
echo basename($path,".CSV");
?>

OutPut :-
filename.CSV
filename

OR

// you also use pathinfo() function .

$file_name = pathinfo('filename');

echo $file_name['dirname'], "\n";
echo $file_name['basename'], "\n";
echo $file_name['extension'], "\n";
echo $file_name['filename'], "\n"

==> Check this Demo Link :-
https://eval.in/930790

Nimesh Patel
  • 796
  • 1
  • 7
  • 23