Page 1 of 1

Truncate problem

Posted: Tue Feb 03, 2004 9:05 pm
by S_henry
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

Posted: Wed Feb 04, 2004 12:16 am
by S_henry
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..

Posted: Wed Feb 04, 2004 12:26 am
by Michael 01
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. :D

Truncate problem

Posted: Thu Feb 05, 2004 8:19 pm
by S_henry
Thanx..so simple.

Posted: Fri Feb 06, 2004 3:11 am
by twigletmac
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:

Code: Select all

$path_parts = pathinfo($file_name);
$file_name_no_extension = basename($file_name, '.'.$path_parts['extension']);
Mac

Posted: Fri Feb 06, 2004 3:13 am
by Michael 01
I have heard of the pathinfo function, but never the baseline. I love coming here because a person learns something new everyday. :D