hi

please help me by this example.

I have this html code and I want to keep only img tag in td tag


$html='<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><div class="big"> SOME HTML CODE HTML CODE <img src="a.jpg"> SOME HTML CODE HTML CODE </div></td>
    <td><div class="big"> SOME HTML CODE HTML CODE <img src="b.jpg"> SOME HTML CODE HTML CODE </div></td>
  </tr>
</table>';
	$html = preg_replace('#<div class="ggg">(.*?)</div>#', '', $html);
echo $html;

output of this code is:


<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td></td>
    <td></td>
  </tr>
</table>

output that I want must be:

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><img src="a.jpg"></td>
    <td><img src="b.jpg"></td>
  </tr>
</table>

any one can help me by changing in php code?

thanks

    Will there always be an img tag, or do you need to handle either case?

      some times there is not img tag.
      if there is img tag showes it
      if there is not image tag showes empty content in td.

        I'm thinking then that you might want to use [man]preg_replace_callback/man so that you can have the callback function process the matched sub-pattern to extract any <img>.

          may you please help me by correct my code when there are img tag always

            Write a Reply...