Hi folks,
I think I need your help really quickly.
I have the following problem:
I'm trying to extract all words ending on eg. UNG from a binary file looking like:
[quote]ABSPEISENN9ABSPENSTIGú/ABSPERRENÈ;ABSPERRGITTERý;ABSPERRHAHNý;ABSPERRHAHNEý;ABSPERRHAHNEEN‚<ABSPERRKETTEú2ABSPERRUNG6=ABSPERRVENTILú7ABSPIELú9ABSPIELENï@ABSPLITTERNú@ABSPRACHEúBABSPRACHEGEMASSHCABSPRECHEN´EABSPREIZENSFABSPRENGENúDABSPRINGEN¹JABSPRITZENúGABSPRUNGõMABSPRUNGBALKENúIABSPULENúMABSTAINúQABSTAMMENúVABSTAMMUNGQABSTAMMUNGEN¸QABSTAMMUNGSLEHREúYABSTANDúmABSTANDENÄVABSTANDSSUMMEúoABSTATTEN:XABSTAUBEN$ZABSTAUBERÀZABSTAUBERINÀZABSTAUBERINEN$ZABSTAUBERSúrABSTAUBERTORútABSTECHENü]ABSTECHERü]ABSTECHERSw^ABSTECKENúxABSTEHEN£_ABSTEHENDEÙÂABSTEHENDENúzABSTEIGEú|ABSTEIGENNGENCNCVME:0( ÷íàÕÌú¤
trying to extract sprecial words from a binary file...
Moderator: General Moderators
preg_match() can probably do what you are looking for.
Code: Select all
$res=`strings $filename| grep 'ung\$'`;
echo $res;
//Or if you want to script it:
Results:
Not sure that fits your exact needs (hit 25 hada small b also in it), but change around to fit your needs. Need comments?
Code: Select all
<pre>
<?php
$filename = "the.file";
$handle = fopen ($filename, "rb");
$s = fread ($handle, filesize ($filename));
fclose ($handle);
echo 'This is the file: '.$s.'<br>';
print_r(thewords($s));
function thewords($s,$needles='UNG') {
foreach (preg_split('/[^\w]/',$needles) as $needle) {
$i = $pcur = $pfound = 0;
while ($pfound !== false && $needles !== '') {
$pfound = strpos(substr($s,$pcur),$needle);
if ($pfound !== false) {
$index = $pfound+$pcur;
$pcur += ($pfound+strlen($needle));
$charsallowed='ABCDEFGHIJKLMOPQRSTUVWXYZ';
$e = 1;
$check = TRUE;
while ($check != FALSE) {
if (strspn(substr($s,$index-$e,$e),$charsallowed)) { $e++; } else { $check = FALSE; }
}
$i++;
$pp[$i] = substr($s,$index-$e+1,$e-1).'UNG';
}
}
}
if (isset($pp)) { ksort($pp); return $pp; }
return false;
}
?>Code: Select all
This is the file: BSPEISEN...cut...EGRAFIEREN
Array
(
ї1] => ABSPERRUNG
ї2] => GABSPRUNG
ї3] => ABSPRUNG
ї4] => VABSTAMMUNG
ї5] => ABSTAMMUNG
ї6] => ABSTAMMUNG
ї7] => ABSTIMMUNG
ї8] => BABSTIMMUNG
ї9] => ABSTIMMUNG
ї10] => ABSTIMMUNG
ї11] => ABSTIMMUNG
ї12] => ABSTOSSUNG
ї13] => ABSTOSSUNG
ї14] => ABSTRAFUNG
ї15] => ABSTRAFUNG
ї16] => ABSTRAHLUNG
ї17] => ABSTUFUNG
ї18] => ABSTUFUNG
ї19] => ABSTUTZUNG
ї20] => STRAFUNG
ї21] => ABTEILUNG
ї22] => ABTEILUNG
ї23] => YABTEILUNG
ї24] => YABTEILUNG
ї25] => ABTEILUNG
ї26] => ABTEILUNG
)