-1

I am parsing an xml feed from a client's event system that does not have a "category" field, so I'd like to have them just append categories to the end of the description field in my designated structure, and then extract them from it and then cut them out of that field afterwards.

Here's an example of what the xml field might look like:

<description>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Pellentesque tempus, purus vel fringilla viverra, mauris diam interdum
lorem, at lobortis lacus augue at neque. Vivamus porttitor sem nec
leo at neque.{!sample-category!}{!other-sample-category!}</description>

Right now, because the structure is nested, I'm setting the variable for the description like this: $event_description = $xml->children()->children()->description;

So I am assuming that I would need to grab my variables from there and set php vars from them, and then trim the $event_description string. I just don't know how. :)

Helpful note: there will only be a handful of categories, so I can literally search for {!sample-category!} rather than looking for anything between {!!}

Thanks for your help!

1 Answers1

1

Take a look at this Q/A

How to check if a string contains specific words?

In your case :

if (strpos($a,'{!sample-category!}') !== false) {
    echo 'true';
}

Since the categories are after some content, you do not have to fear the case where the match is at the beginning of the string.

Community
  • 1
  • 1
agrum
  • 407
  • 2
  • 16