Page 1 of 1

strip text from a string

Posted: Fri Apr 25, 2003 7:49 pm
by wallabee
i have a bunch of files that are basically named "totalDesiredString.txt" where "DesiredString" is a varying name throughout the files. What I'd like to do is take "totalDesiredString.txt", and strip it of it's total and it's .txt, leaving only "DesiredString", which can be used to present relevent text boxes. IE "DesiredString's Number of Pictures" blah blah.

Anyone know of a function that does what I'm doing, or a function that will, through a series of processes, lead me to where I need to be? Thanks, you've all been a great help this far.

Posted: Fri Apr 25, 2003 8:04 pm
by m3mn0n
Have you looked at the Manual's filesystem functions? fopen and it's associated funcs should help you out. :)

Posted: Fri Apr 25, 2003 8:09 pm
by wallabee
i guess i don't really see how this would apply.

we're dealing strictly with strings. if you want to, pretend that "totalBlah.txt" isn't a text file, it's just a string which is "totalBlah.txt". I want to take "totalBlah.txt" and turn it into the string "Blah".

accessing the text files and what's within them I have no problem with.

thanks for the input anyway, though.

Posted: Fri Apr 25, 2003 8:28 pm
by patrikG
preg_match("/total(\w).txt/",$myFileName,$matches) should return an array "$matches" which contains any sequence of characters inbetween "total" and ".txt".

Posted: Fri Apr 25, 2003 9:14 pm
by McGruff
$string = substr_replace($string, 5, -4);

Posted: Sat Apr 26, 2003 5:26 am
by twigletmac
If total and .txt are constant:

Code: Select all

$filename = 'totalDesiredString.txt';
$string = str_replace(array('total', '.txt'), '', $filename);
Mac