Truncate problem
Moderator: General Moderators
Truncate problem
I have a simple question. Let say I have one string (e.g. 'football') but I just want to display(echo) 'foot'. How can I do that? Any idea?
Truncate problem
Let me explain more detail. Actually in my table, 1 of my data is the file name (eg: abc.txt, def.ppt). In my page, I only want to display 'abc' or 'def' without their extension. So, any idea pls..
- Michael 01
- Forum Commoner
- Posts: 87
- Joined: Wed Feb 04, 2004 12:26 am
There are several methods for this and my recommendations are the following:
ereg_replace
OR
str_replace
Both functions can work the way you wish without creating a function of your own, however if you wish to use upload scripts, creating your own full function extension mask manager may be a good idea as well.
ereg_replace
OR
str_replace
Both functions can work the way you wish without creating a function of your own, however if you wish to use upload scripts, creating your own full function extension mask manager may be a good idea as well.
Truncate problem
Thanx..so simple.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You can also use [php_man]basename[/php_man](), by itself if the extension will always be the same or in conjunction with [php_man]pathinfo[/php_man]() if it will be variable. E.g:
Mac
Code: Select all
$path_parts = pathinfo($file_name);
$file_name_no_extension = basename($file_name, '.'.$path_parts['extension']);- Michael 01
- Forum Commoner
- Posts: 87
- Joined: Wed Feb 04, 2004 12:26 am