Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The proper way to do this is to use PHP's <a href="http://php.net/DOMDocument" rel="nofollow"><code>DOMDocument</code></a> class to extract what you need. Here is a working solution:</p> <pre><code>$str = '&lt;eerste_kwartier&gt;naam leeg&lt;/eerste_kwartier&gt;'; $doc = new DOMDocument(); $fragment = $doc-&gt;createDocumentFragment(); $fragment-&gt;appendXML( $str); $doc-&gt;appendChild( $fragment); $xpath = new DOMXPath( $doc); $node = $xpath-&gt;query( '/eerste_kwartier')-&gt;item(0); $text = $doc-&gt;createTextNode( $node-&gt;textContent); $node-&gt;nodeValue = ''; // Clear out the contents of the tag // Get the text before and after the replacement $start = strpos( $text-&gt;wholeText, 'leeg'); $before = $text-&gt;substringData( 0, $start); $after = $text-&gt;substringData( $start + strlen( 'leeg'), strlen( $text-&gt;wholeText)); // Put the text back, minus the replacement, with something else added $node-&gt;appendChild( $doc-&gt;createTextNode( trim( $before))); $node-&gt;appendChild( $doc-&gt;createTextNode( "Something Else")); $node-&gt;appendChild( $doc-&gt;createTextNode( $after)); echo htmlentities( $doc-&gt;saveXML()); </code></pre> <p>This <a href="http://viper-7.com/X8my8p" rel="nofollow">outputs</a>:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;eerste_kwartier&gt;naam Something Else&lt;/eerste_kwartier&gt; </code></pre> <p>For the second test case, it <a href="http://viper-7.com/C0bUVz" rel="nofollow">will output</a>:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;eerste_kwartier&gt;Something Else leeg&lt;/eerste_kwartier&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload