Page 1 of 1

elimination of <span> tags

Posted: Thu Jun 18, 2009 5:42 am
by revbackup
my variable is like this:

$var='<td>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()">
<span class="google-src-text" style="direction: ltr; text-align: left">
<span style="font-weight: bold; font-style: italic;">
<span style="text-decoration: underline;">Frequency</span>:
</span>The system will launch the task every X minutes.</span>
<span style="text-decoration: underline;">
<span style="font-weight: bold; font-style: italic;">Fréquence:</span>
</span> Le système permettra de lancer la tâche toutes les X minutes.</span> </td>';

I want to remove the <span style>...</span> tags if it is inside a <span class>...</span tag>.
So, in my $var, I have to remove the ones which are colored green and blue.
but I need to remove first the one in green, and then remove the one in blue.

I have a code here
// Replaces vertical whitespace characters with single spaces so the pattern will work
$xml= preg_replace('/\v+/', ' ', $xml);
// Pattern to find a single style span within a class span
$pattern = '#(<span\s+class\s*=[^>]+>)(.*?)(<span\s+style\s*=[^>]+>(.*?)</span>)(.*?)(</span>)#';
// Reconstructs the string without the style span
$xml= preg_replace($pattern, '\1\2\5\6', $xml);
But this one only removes a single style span within a class span...

Can you please add something to my code so that I can remove the two span style tags within
the span class? but it should be, the one in green (the inner span style) should be first removed
then, after that, the one in blue (the outer span style) should be removed, so that I have this as the
content of my new variable.:

$var='<td>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()">
<span class="google-src-text" style="direction: ltr; text-align: left">
The system will launch the task every X minutes.</span>
<span style="text-decoration: underline;">
<span style="font-weight: bold; font-style: italic;">Fréquence:</span>
</span> Le système permettra de lancer la tâche toutes les X minutes.</span> </td>';