•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,991 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,307 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 180 | Replies: 5
![]() |
Hi all,
I just need to delete .jpg form the end of a variable stored like this:
$name = $_POST["name"];
Thanks
Max
ps
echo stristr($name, '.', true); // As of PHP 5.3.0, outputs *content of string BEFORE the first full stop*
dosnt work. im guessing its because my php on my server is a different version than 5.3.0
this is the code i tested just to make sure it wasnt a silly mistake
I just need to delete .jpg form the end of a variable stored like this:
$name = $_POST["name"];
Thanks

Max
ps
echo stristr($name, '.', true); // As of PHP 5.3.0, outputs *content of string BEFORE the first full stop*
dosnt work. im guessing its because my php on my server is a different version than 5.3.0
this is the code i tested just to make sure it wasnt a silly mistake
$email = 'USER@EXAMPLE.com'; echo stristr($email, 'e'); // outputs ER@EXAMPLE.com echo stristr($email, 'e', true); // As of PHP 5.3.0, outputs US
Last edited by MaxMumford : Jul 1st, 2008 at 3:12 pm.
Economizerz Hosting
Price Beater Promise
10% Cheaper Hosting, & Double Bandwidth and Web Space
Click here to apply
Price Beater Promise
10% Cheaper Hosting, & Double Bandwidth and Web Space
Click here to apply
Ah okay that works fine. I actually found this solution just as you sent your reply which is:
That works too but only gets rid of the last 4 letters. In my case im sure they are all jpg but other people may want to use another method.
Thanks for your help.
And thanks allexxei too
$name = substr($_POST['name'], 0, -4); //gets rid of last 4 characters. remove the ", 0" to get rid of first 4 characters. Refer to http://uk2.php.net/manual/en/function.substr.php
That works too but only gets rid of the last 4 letters. In my case im sure they are all jpg but other people may want to use another method.
Thanks for your help.
And thanks allexxei too
Last edited by MaxMumford : Jul 1st, 2008 at 3:20 pm.
Economizerz Hosting
Price Beater Promise
10% Cheaper Hosting, & Double Bandwidth and Web Space
Click here to apply
Price Beater Promise
10% Cheaper Hosting, & Double Bandwidth and Web Space
Click here to apply
•
•
Join Date: Jul 2008
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 1
function remove_ext($str) {
$noext = preg_replace('/(.+)\..*$/', '$1', $str);
print "input: $str\n";
print "output: $noext\n\n";
}
I found it on php.net
Must work very good and shoul remove any extension
You should remove the prints and addd a return line
function remove_ext($str) {
$noext = preg_replace('/(.+)\..*$/', '$1', $str);
return $noext;
}
$noext = preg_replace('/(.+)\..*$/', '$1', $str);
print "input: $str\n";
print "output: $noext\n\n";
}
I found it on php.net
Must work very good and shoul remove any extensionYou should remove the prints and addd a return line

function remove_ext($str) {
$noext = preg_replace('/(.+)\..*$/', '$1', $str);
return $noext;
}
Last edited by allexxei : Jul 1st, 2008 at 3:21 pm.
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 238
php Syntax (Toggle Plain Text)
$filename = "test123.jpg"; $file = substr($filename,0,strpos($filename,".")); echo $file;
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
kk. Its me who is uploading the pictures anyway so it should be fine. But in future ill probably need to use it again 
Thanks everybody

Thanks everybody
Economizerz Hosting
Price Beater Promise
10% Cheaper Hosting, & Double Bandwidth and Web Space
Click here to apply
Price Beater Promise
10% Cheaper Hosting, & Double Bandwidth and Web Space
Click here to apply
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Open In New Window Php (PHP)
- Instantiating an Object of a Class Confusion (Java)
- Need Help with JButtons Functionality (Java)
- Inventory program part 5 help (Java)
- modify script (Perl)
Other Threads in the PHP Forum
- Previous Thread: Lab scheduling
- Next Thread: Changing server folder name using PHP



Linear Mode