Re: preg split question
| From: | Jonathan Pitcher | Date: | Thu, 27 Mar 2003 15:03:46 +0000 |
| Subject: | Re: preg split question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-141228@lists.php.net to get a copy of this message | ||
Torsten,
You could use explode on the file name and then only read in the sections that you want:
$FileName = "Benutzer_OVE_CRA.php";
$Part1 = explode("_", $FileName_);
$TotalPart1 = count($Part1);
$Wanted_File_Pieces = array();
// C = 2 so that it will skip the Benutzer part of the filename and will be equal to total before the end is reached.
for ($C=2; $C<$TotalPart1; $C++)
{
$Wanted_File_Pieces[($C - 2)] = $Part1[($C - 1)];
}
$Part2 = explode(".", $Part1[$TotalPart1]);
$Total2 = count($Wanted_File_Pieces);
$Wanted_File_Pieces[$Total2] = $Part2[0];
$NewFileName = join("_", $Wanted_File_Pieces);
It may be possible to do it with preg_split, I am not as familiar with that function as I would like to be.
Hope this helped show you another way to do what you where wanting to do.
Jonathan Pitcher
On Thursday, March 27, 2003, at 08:39 AM, Torsten Rosenberger wrote:
Hello i'd like to split Benutzer_CRA.php to get CRA but sometimes the files are called Benutzer_OVE_CRA.php and therefore the result schould OVE_CRA how cann i tell preg_split to split the string at the first occurence of _ and before .php BR/Torsten -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php