ballhogjoni Posted September 26, 2008 Share Posted September 26, 2008 It seems that I can't replace this string: <tr><td height="290" colspan="3"></td></tr><tr><td height="163" valign="top" colspan="3"></td></tr> this is my preg_replace() $sReplaceHTML = preg_replace( '%<tr><td height="290" colspan="3"></td></tr><tr><td height="163" valign="top" colspan="3"></td></tr>%','',$sStripDOC ); what am I doing wrong? Yes the code contains the pattern I want to replace. Quote Link to comment https://forums.phpfreaks.com/topic/125895-solved-cant-preg_replace-this-string/ Share on other sites More sharing options...
redarrow Posted September 26, 2008 Share Posted September 26, 2008 can u provide a proper example please............ Quote Link to comment https://forums.phpfreaks.com/topic/125895-solved-cant-preg_replace-this-string/#findComment-650991 Share on other sites More sharing options...
xtopolis Posted September 26, 2008 Share Posted September 26, 2008 <?php $sStripDOC = '<tr><td height="290" colspan="3"></td></tr><tr><td height="163" valign="top" colspan="3"></td></tr>'; $sReplaceHTML = preg_replace( '%<tr><td height="290" colspan="3"></td></tr><tr><td height="163" valign="top" colspan="3"></td></tr>%','',$sStripDOC ); var_dump($sReplaceHTML); //outputs string(0) "" ?> The entire string was found, and replaced by '' which you specified in parameter 2 of preg_replace. It is working as intended. Quote Link to comment https://forums.phpfreaks.com/topic/125895-solved-cant-preg_replace-this-string/#findComment-650996 Share on other sites More sharing options...
ballhogjoni Posted September 26, 2008 Author Share Posted September 26, 2008 still in the html code on the web page. Quote Link to comment https://forums.phpfreaks.com/topic/125895-solved-cant-preg_replace-this-string/#findComment-651009 Share on other sites More sharing options...
xtopolis Posted September 26, 2008 Share Posted September 26, 2008 Give us more code Quote Link to comment https://forums.phpfreaks.com/topic/125895-solved-cant-preg_replace-this-string/#findComment-651020 Share on other sites More sharing options...
sasa Posted September 26, 2008 Share Posted September 26, 2008 Ttry $sReplaceHTML = preg_replace( '%<tr><td height="290" colspan="3"></td></tr><tr><td height="163" valign="top" colspan="3"></td></tr>%is','',$sStripDOC );[/code Quote Link to comment https://forums.phpfreaks.com/topic/125895-solved-cant-preg_replace-this-string/#findComment-651192 Share on other sites More sharing options...
ballhogjoni Posted September 26, 2008 Author Share Posted September 26, 2008 I think the problem is that there is whitespace in the string that i didn't include before. Here is what the string really looks like: <tr> <td height="290" colspan="3"> </td> </tr> <tr> <td height="163" valign="top" colspan="3"> </td> </tr> How do you get rid of whitespace? Quote Link to comment https://forums.phpfreaks.com/topic/125895-solved-cant-preg_replace-this-string/#findComment-651242 Share on other sites More sharing options...
BSlepkov Posted September 26, 2008 Share Posted September 26, 2008 I just posted the results of my struggles with preg_ functions at http://www.phpfreaks.com/forums/index.php/topic,218141.0.html You should find that somewhat instructive. Also, with regards to any possible white spaces, your script should look more like this: preg_replace( '/<tr>\s?<td height="290" colspan="3">\s?</td>\s?</tr>\s?<tr>\s?<td height="163" valign="top" colspan="3">\s?</td>\s?</tr>/','',$sStripDOC ) I'm no expert, but I think that should help you somewhat. BTW, what's with the '%' at the start and end of your preg pattern? Quote Link to comment https://forums.phpfreaks.com/topic/125895-solved-cant-preg_replace-this-string/#findComment-651270 Share on other sites More sharing options...
ballhogjoni Posted September 26, 2008 Author Share Posted September 26, 2008 thanks, the % is the delimeter. I know of three different delimeters. You can use them as long as the delimeter is the same as the end. IE.. /your pattern/ or #your pattern# or %your pattern% Whats nice about using #your pattern# or %your pattern% is that you don't have to escape the forwardslash in your pattern. Quote Link to comment https://forums.phpfreaks.com/topic/125895-solved-cant-preg_replace-this-string/#findComment-651274 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.