1

I want to change this:

<div>
  <div>
    <div id="myList">
      <table><tr><td></td></tr></table>
    </div>
  </div>
</div>

Into this:

<table><tr><td></td></tr></table>

What would the preg_replace() be? I have tried the following but to no avail:

$result = preg_replace('#<div(.*?)(?! id="myList")>(.*?)</div>#is', '', $result);
0

2 Answers 2

4

You can use strip_tags

$string = '<div>
  <div>
    <div id="myList">
      <table><tr><td></td></tr></table>
    </div>
  </div>
</div>';

echo strip_tags($string, '<table><tr><td>');
Sign up to request clarification or add additional context in comments.

1 Comment

Props to you for avoiding the RegEx pony
1

@Reado try this

$s='<div>
  <div>
    <div id="myList">
      <table><tr><td></td></tr></table>
    </div>
  </div>
</div>';
    $replace=str_replace(array('<div>', '<div id="myList">','</div>'),"",$s);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.