Hello dear forum members!
So, with „explode” in PHP I already managed to split up a string into several arrays which I store into $aufgespalten (see below the arrays I put out):
[code]$aufgespalten[0]
<?xml version="1.0" encoding="utf-8"?> Kommentar segment 6$aufgespalten[1]
Kommentar segment 7
$aufgespalten[2]
Kommentar segment 8
$aufgespalten[3]
Kommentar segment 9
$aufgespalten[4]
UEsDBBQAAAAIANGqW0lGCniGFAgAAMswAAAQAAAAaXNoeXVoZXMuYzB6LnRtcO1a3W7bNhs+doHe A+cBw7baVrLut3W8OUmzZkiazHLbw4GWaJsNReojqTjehwG7kO3DTj/sEnaWS9mV7CUlWbIlJ5an LcHWtsjP+/vwIV/yJd3ul1cBQ5dEKir4XnO3s9NEhHvCp3yy14z0uL37afPLXveddvvhg4cPGgci
[…][/code]
Thanks to value $key I know exactly that these are the array numbers as stated.
Anyway, I now want to search in the array $aufgespalten[1]. I want to exclude everything between “<Comment “ and “>”. (below the complete string and what I want to filter out)
[php] Kommentar segment 7 [/php]
[php] severity=“Low” user=“PC” date=“2016-10-30T20:42:56.0922708+00:00” version=“1.0”[/php]
That’s why I would use the following regular expression: [php]@<Comment (.*?)>@[/php]
According to regex101 this should also work - https://regex101.com/r/ZDKVwO/1
But when I use it in my code, nothing is being returned, the array is completely empty. Below is the code I use:
[php]
$regex = ‘@<Comment (.*?)>@’;
preg_match($regex, $aufgespalten[1], $treffer);
foreach ($treffer as $key => $value) {
print “
” . "Der durch RegEx gefundene String ist: " . $value . “
”;
}
[/php]
Thank you very much in advance, that would help my work project immensely
I know that it might be easier dealing with this kind of file (it is a SDLXLIFF file, which is basically an XML) via “$xml=simplexml_load_file” so that I can filter easily for tags etc, but it somehow doesn’t work with the .xliff file to load it into PHP. (Maybe because although it “looks” like an XML the file name is different or something.) Anyway, since I am a complete beginner to PHP, I think it wouldn’t be a bad idea to try out some string functions.
Thank you!