Hi,
ich bräuchte mal Hife um mein Regex Pattern anzupassen.
Ausgabe:
gewünscht wäre aber:
ich bräuchte mal Hife um mein Regex Pattern anzupassen.
HTML-Code:
[...] <tr> <td>Text Text <span>Text</span> Text <strong>Text</strong></td> <td class="text">Text Text <span>Text</span> Text <strong>Text</strong></td> <td>Text Text </td> </tr> [...]
PHP-Code:
$html = 'siehe oben';
$pattern = '/<td(.*?)<\/td>/si' ;
$string = preg_replace_callback ( $pattern, function ($match)
{
$search=array('<', '>');
$replace=array('#OPEN#', '#CLOSE#');
return str_replace($search, $replace, $match[0]);
}, $html ) ;
echo($string);
HTML-Code:
<tr> #OPEN#td#CLOSE#Text Text #OPEN#span#CLOSE#Text#OPEN#/span#CLOSE# Text #OPEN#strong#CLOSE#Text#OPEN#/strong#CLOSE##OPEN#/td#CLOSE# #OPEN#td class="text"#CLOSE#Text Text #OPEN#span#CLOSE#Text#OPEN#/span#CLOSE# Text #OPEN#strong#CLOSE#Text#OPEN#/strong#CLOSE##OPEN#/td#CLOSE# #OPEN#td#CLOSE#Text Text #OPEN#/td#CLOSE# </tr>
HTML-Code:
<tr> <td>Text Text #OPEN#span#CLOSE#Text#OPEN#/span#CLOSE# Text #OPEN#strong#CLOSE#Text#OPEN#/strong#CLOSE#</td> <td class="text">Text Text #OPEN#span#CLOSE#Text#OPEN#/span#CLOSE# Text #OPEN#strong#CLOSE#Text#OPEN#/strong#CLOSE#</td> <td>Text Text </td> </tr>
Kommentar