nfr Posted May 19, 2006 Share Posted May 19, 2006 Hello -How can I replace all instances of "<br>" with "<br />" in a block of text? The "<br>" seems to be crashing my XML feed because there is no "</br>".Thanks and regards,Neil. Link to comment https://forums.phpfreaks.com/topic/10032-search-and-replace-for/ Share on other sites More sharing options...
nfr Posted May 19, 2006 Author Share Posted May 19, 2006 I also need to perform the following on the text:1.) replace all instances of "  " with " "2.) remove all instances of "line start<P></P>line end"3.) remove all instances of "line start<P> </P>line end"4.) replace all instances of "line start<P></P><article>line end" with "<article>"This is to clean up data. How can I do all of this in once hit?Regards,Neil. Link to comment https://forums.phpfreaks.com/topic/10032-search-and-replace-for/#findComment-37276 Share on other sites More sharing options...
kenrbnsn Posted May 19, 2006 Share Posted May 19, 2006 Look at the functions [a href=\"http://www.php.net/str_replace\" target=\"_blank\"]str_replace()[/a] and [a href=\"http://www.php.net/strip_tags\" target=\"_blank\"]strip_tags()[/a].Ken Link to comment https://forums.phpfreaks.com/topic/10032-search-and-replace-for/#findComment-37282 Share on other sites More sharing options...
nfr Posted May 19, 2006 Author Share Posted May 19, 2006 How can I search on a line start and a line end?I've got the following to replace the "<BR>" tags with "<BR />" but how can I remove a line such as:line start<P> </P>line endRegards,Neil. Link to comment https://forums.phpfreaks.com/topic/10032-search-and-replace-for/#findComment-37307 Share on other sites More sharing options...
kenrbnsn Posted May 19, 2006 Share Posted May 19, 2006 For that you need to use the regular expression functions. I really can't help you there, since I still can't understand them myself.Ken Link to comment https://forums.phpfreaks.com/topic/10032-search-and-replace-for/#findComment-37315 Share on other sites More sharing options...
nfr Posted May 20, 2006 Author Share Posted May 20, 2006 Anyone?Thanks,Neil. Link to comment https://forums.phpfreaks.com/topic/10032-search-and-replace-for/#findComment-37328 Share on other sites More sharing options...
shoz Posted May 20, 2006 Share Posted May 20, 2006 [code]<?php$string = <<<LLLjdsdssdsd <br>jdhjdshj dsjdhsj <br /><p></p><p> </p><p></p><article><br><br><p></p>LLL;$match = array();$replace = array();$match[] = '#<br>#i';$replace[] = '<br />';$match[] = '#^<p> </p>(?:\r?\n|\Z)#im';$replace[] = '';/** * this has to be added to the array * after the <p> </p> */$match[] = '# #i';$replace[] = ' ';$match[] = '#^<p></p>(\r?\n|\Z)#im';$replace[] = '';$match[] = '#^<p></p><article>$#im';$replace[] = '<article>';print preg_replace($match, $replace, $string);?>[/code]output[code]jdsdssdsd <br />jdhjdshj dsjdhsj <br /><article><br /><br />[/code] Link to comment https://forums.phpfreaks.com/topic/10032-search-and-replace-for/#findComment-37341 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.