Removing extensions from filename [duplicate] - php

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How remove extension from string (only real extension!)
Remove file extension on file upload
I am looking for ways to remove extensions but from what i found in google are really bad examples on how to do it.
$from = preg_replace('/\.[^.]+$/','',$from);
Something like this, any idea on how to do it?

Check out the basename function, which should do that for you. Note that it will also strip any folder names in the path.

Related

PHP Windows - Return drive letter from path [duplicate]

This question already has answers here:
PHP detect (or remove) current drive letter?
(2 answers)
Closed 5 years ago.
I'm trying to get the drive letter from a path in PHP windows.
I'm in this directory:
c:\Program Files\Adobe\
and I want to return:
c
What's the best way to do this? Is there an alternative to parse_url(), but for local paths (and usable under Windows?).
Use substr function from php.
$dir = 'c:/...';
$letter = substr($dir,0,1);
You could also use explode in php, which actually works similar to split.
$drive = explode(":",$path)[0];

Remove File extension and underscore [duplicate]

This question already has answers here:
PHP, get file name without file extension
(18 answers)
Closed 6 years ago.
Is that possible to remove the file extension type from file name and underscore? For example: File name is MTK_USB_All_v1.0.1.zip But I want to show it as
MTK USB All v1.0.1
Ex: https://androiddatahost.com/upload/Amomp
Right now Im using
<?php echo $name; ?>
to show the file name. I also want to show the alternate name of the file without file extension and underscore.
Is that possible?
You can try this
$filename=basename($pathinfo);
$final_filename=str_replace('_','',$filename);
To Show only the Filename you can use pathinfo.
$filename = pathinfo('filename.zip', PATHINFO_FILENAME);
To replace underscore with blank space you can use str_replace();

Read ini file in PHP, not parse [duplicate]

This question already has answers here:
PHP: Escape illegal chars in .ini-files
(2 answers)
Closed 1 year ago.
When using parse_ini_file, it will attempt to read and understand the ini file. I'm looking for a solution that will read the file, place it into arrays much like parse_ini_file does, however I don't want it to get to the special characters in my ini file and spit an error that it can't parse them. Could anyone point me in the right direction?
ini file for reference:
[IMPORT]
email=email#thisisanemail.com
location=
Description=Order Form
name=*.xls*
matrixfile=
matrix_field=
matrix_disc_type_column=
matrix_disc_percentage_column=
fixed=XLS
separator=|
RowTerminator=
headerrows=13
footerrows=0
maxexcelcolumns=7
If I parse this, it gets stuck on the seperator "|" but I need that there.
If you use parse_ini_file with the scanner_mode parameter to specify INI_SCANNER_RAW, then option values will not be parsed (see
https://www.php.net/manual/en/function.parse-ini-file.php).

How do I stripslashes from something I include in PHP? [duplicate]

This question already has answers here:
Magic quotes in PHP
(12 answers)
Closed 8 years ago.
I am working on a website and I have a php editor that automatically adds \ to certain things. I was aware of the stripslashes() function and I know it can be used in a way such as: stripslashes($test) but I am including something and I do not know how to strip the slashes from the Page I am including. Here is my include code that I am using:
<?php include $_SERVER['DOCUMENT_ROOT']."/newseditor/BlogTitle.php"; ?>
So how would I stripslashes from this? Thanks for reading and I appreciate all help I recieve.
You are suffering from PHP's magic quotes, and here is how to turn it off:
http://www.php.net/manual/en/security.magicquotes.disabling.php

PHP '#' syntax? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Reference - What does this symbol mean in PHP?
Found an image upload script on the net and I'm just modifying it to my needs. It contains lines like the one below that begins with an # symbol. I'm more of a javascript/jQuery guy so can someone explain what this '#' syntax is all about please?
#move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
or error('receiving directory insuffiecient permission', $uploadForm);
Please note I'm not asking what the above lines do, just about the functionality of the # symbol
It stops error messages, see here:
http://us3.php.net/manual/en/language.operators.errorcontrol.php
It suppresses PHP errors, generally it'll be used by lazy developers as a substitute to isset()

Categories