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>

Link to comment
Share on other sites

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');

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.