How to get values inside <![CDATA[values]] > using php DOM?

Viewed 57580

How can i get values inside <![CDATA[values]] > using php DOM. This is few code from my xml.

     <Destinations>

        <Destination>
            <![CDATA[Aghia Paraskevi, Skiatos, Greece]]>
            <CountryCode>GR</CountryCode>
        </Destination>

        <Destination>
            <![CDATA[Amettla, Spain]]>
            <CountryCode>ES</CountryCode>
        </Destination>

        <Destination>
            <![CDATA[Amoliani, Greece]]>
            <CountryCode>GR</CountryCode>
        </Destination>

        <Destination>
            <![CDATA[Boblingen,  Germany]]>
            <CountryCode>DE</CountryCode>
        </Destination>

  </Destinations>
6 Answers
function inBetweenOf(string $here, string $there, string $content) : string {
    $left_over = strlen(substr($content, strpos($content, $there)));
    return substr($content, strpos($content, $here) + strlen($here), -$left_over);
}

Iterate over "Destination" tags and then call inBetweenOf on each iteration.

$doc = inBetweenOf('<![CDATA[', ']]>', $xml);
Related