I want to remove all <td></td> from source String in PHP. But don't know how to do it. I tried but it does not work.
preg_replace('/(?:<|<)td(?:>|>)(?:<|<)\/td(?:>|>)/', '', $sourceString);
Please tell me how to do it in PHP
<?php
$out = preg_replace('/(?:<|<)td(?:>|>)(?:<|<)\/td(?:>|>)/', '', $sourceString);
?>
if your regex is correct in $out is your result :)
but there is one more simple way strip tags
<?php
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
echo "\n";
// Allow <p> and <a>
echo strip_tags($text, '<p><a>');
?>
your pattern is looking for
<td></td>
but it won't find
<td>test</td>
There is a litte "|" missing. That one fits:
<?php
$out = preg_replace('/(?:<|<)td(?:>|>)|(?:<|<)\/td(?:>|>)/', '', $sourceString);
?>
you can try it here https://de.functions-online.com/preg_replace.html
<td></td>2.<td>blahblah</td>so what u want to recieve? 1. empty string 2. blahblah or empty string?