Page 1 of 1
delete characters?
Posted: Fri Jul 28, 2006 6:56 pm
by jasondavis
I have a text file like with entries like this
10692336 217]
albafghffg@hotmail.com:0943689
I need to fine these entries 1 per line from a text file and delte everything to the left side of
]
Posted: Fri Jul 28, 2006 7:33 pm
by Burrito
moved to regex.
you'll need a regular expression to location the section you want to keep and strip out the rest.
if you can tell me what you want to keep, i can help you with the pattern.
Re: delete characters?
Posted: Wed Aug 09, 2006 10:00 am
by christian_phpbeginner
jasondavis wrote:I have a text file like with entries like this
10692336 217]
albafghffg@hotmail.com:0943689
I need to fine these entries 1 per line from a text file and delte everything to the left side of
]
hi, I wonder if you have found the solution yet. But, what a coincedence, your case is just mine also.
So, I have the code:
Code: Select all
$strTest = "10692336 217] albafghffg@hotmail.com:0943689";
//pay attention on these 2 different patterns in order to do something else different but using the same $strTest
$patternStrTest = '/(\d+\s\d+)\W/';
$patternRetrieveFrontNumber= '/\][a-z\s\@\.\w\:]+/';
preg_match_all($patternStrTest, $strTest, $arrayTest);
foreach($arrayTest as $line) {
//Output A
echo "<pre>";
print_r ($line);
echo "</pre>";
}
$deleteNum= preg_replace ($patternStrTest, '', $strTest);
//Output B
echo $deleteNum;
$deleteEmail = preg_replace ($patternRetrieveFrontNumber, '', $strTest);
//Output C
echo $deleteEmail;
Output A:
Code: Select all
Array
(
[0] => 10692336 217]
)
Array
(
[0] => 10692336 217
)
Output B:
Output C:
Output C is what you want, I think. Read the tutorial for REGEX, because each time you meet new task with different pattern, then you'll need different pattern of REGEX. So, learning REGEX would be very worthy !
Good luck,
Chris