'How to extract Data from Cdata in XML (WP All Import)
Hi I'm using WP All Import to process an XML Feed of events. The feed does not include the venue as a separate path but in CDATA which looks like this:
<name>
<![CDATA[ 31 May 2022 - 19:00 @ Strand Arts Centre - (opening time 18:00) Test Show please ignore this ]]>
</name>
The venue always appears after the @ and before – So I assume I need to run some sort of pre replace to extract everything between the two symbols, but not sure how to do this. Any help appreaciated.
Solution 1:[1]
I managed to solve it myself by adding this function:
function get_string_between ($str) {
$from = '@';
$to = '-';
$string = substr($str, strpos($str, $from) + strlen($from));
if (strstr ($string,$to,TRUE) != FALSE) {
$string = strstr ($string,$to,TRUE);
}
return $string;
}
and then added this to the wp all import field for venue:
[get_string_between({name})]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ladygeekgeek |
