<trans-unit id="8">
<source>Special settings for:</source>
<target>Special settings for:</target>
</trans-unit>
I am trying to get the ID and the contents of the target tag. The above structure is repeated many times in the XML I am trying to parse.
I am currently using the expression below, but it doesn’t return anything but empty arrays:
preg_match_all('#<trans-unit id="(.*)">(.*)<target>(.*)</target>(.*)</trans-unit>#Ui', $xml, $matches);
You can use the /s pattern modifier to make the dot (.*) match all characters including newline characters. By default PCRE treats the string as a long one-line one.
http://php.net/manual/en/reference.pcre.pattern.modifiers.php
So in the above example: