soma56 Posted August 31, 2010 Share Posted August 31, 2010 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 https://forums.phpfreaks.com/topic/212198-preg_replace-trying-to-remove-between-content-between-a-specific-tag/ Share on other sites More sharing options...
jayarsee Posted August 31, 2010 Share Posted August 31, 2010 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 https://forums.phpfreaks.com/topic/212198-preg_replace-trying-to-remove-between-content-between-a-specific-tag/#findComment-1105731 Share on other sites More sharing options...
soma56 Posted August 31, 2010 Author Share Posted August 31, 2010 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 https://forums.phpfreaks.com/topic/212198-preg_replace-trying-to-remove-between-content-between-a-specific-tag/#findComment-1105743 Share on other sites More sharing options...
jayarsee Posted August 31, 2010 Share Posted August 31, 2010 It would be this echo preg_replace('/<.+>(.+)<\/.+>/', 'test', $raw_data); What I was asking you to try would be the entire regex. Link to comment https://forums.phpfreaks.com/topic/212198-preg_replace-trying-to-remove-between-content-between-a-specific-tag/#findComment-1105821 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.