Jump to content

preg_replace - trying to remove between content between a specific tag...


soma56

Recommended Posts

What am I doing wrong?

 

<?PHP
echo preg_replace('#(<td class="results" style="border-width: 0px 0px 1px;">).*?(</td>)#', 'test', $raw_data);
?>

 

If the contents of $raw_data has:

<td class="results" style="border-width: 0px 0px 1px;">THERE IS SOME CONTENT HERE</td>

 

should it not be replaced as so? :

<td class="results" style="border-width: 0px 0px 1px;">test</td>

Try using this as your regex string:

 

/<.+>(.+)<\/.+>/

 

This will work as long as your content isn't expected to contain angle brackets.

 

And I have to mention, if it's at all possible to do this in JavaScript instead that would be better. If you include jQuery, you could give the <td id="contentcell">text</td>

 

and in JavaScript do

 

$('#contentcell').html('new text');

thanks, the page doesn't contain any angle brackets. The script isn't removing the content and I'm receiving no error messages. The source code and page still reflects the content that I'm trying to replace. This is what I have tried:

 

echo preg_replace('#(<td class="results" style="border-width: 0px 0px 1px;">)/<.+>(.+)<\/.+>/(</td>)#', 'test', $raw_data);

echo preg_replace('!(<td class="results" style="border-width: 0px 0px 1px;">)/<.+>(.+)<\/.+>/(</td>)!', 'test', $raw_data);

echo preg_replace("#(<td class=\"results\" style=\"border-width: 0px 0px 1px;\">)/<.+>(.+)<\/.+>/(</td>)#", 'test', $raw_data);

 

 

I'm not very good at preg_match and I know this issue has something to do with the code between the specific tags I'd like to remove.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.