I have this string
<itcc-ci:somevariabletext contextRef="cntxCorr_i" unitRef="eur" decimals="0">2020265</itcc-ci:somevariabletext>
I want remove all characters and print only 2020265
.
How can I do that? I have used str_replace
but it did not work. Any ideas?
I have use a htmlspecialchars()
function, but now I have no idea. My string now is
<itcc-ci:somevariabletext contextRef="cntxCorr_i" unitRef="eur" decimals="0">2020265</itcc-ci:somevariabletext>
3
Answers
My suggestion is that we take advantage of the fact that this number is between the ‘>’ and ‘<‘ characters. If this is always the rule, then such code will help:
It is XML, so parse it as XML.
This will produce a warning since it is not a full document and is missing the namespace declaration. You should parse the full document and use XML operations to extract the data that you want, rather than picking fragments out of the middle.
See: https://www.php.net/manual/en/book.dom.php
Your data is missing fundamental information. Assuming you have it all, and you just didn’t share it here:
Demo