prakash Posted October 1, 2007 Share Posted October 1, 2007 how can I ignore html tags with regex Quote Link to comment https://forums.phpfreaks.com/topic/71432-validating-html-tags/ Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 you could remove them ie <?php $html = '<head> <body onload="test();"> <b>testing</b> </body>'; $html= preg_replace('/<[^>]*>/i', '', $html); echo $html; echo "<br>View Source, to check tags have been removed"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/71432-validating-html-tags/#findComment-359854 Share on other sites More sharing options...
prakash Posted October 2, 2007 Author Share Posted October 2, 2007 thanks for the code and now I need to know how can I replace multiple line breaks with single one. for eg: <?php $html = '<div id="article"> <h1>Five More Months Tacked Onto XP Availability Roadmap</h1> <h2> By <a href="mailto: sfulton@betanews.com">Scott M. Fulton, III</a>, BetaNews </h2> <h3>September 28, 2007, 1:31 PM</h3> <span id=intelliTxt> <p><b>Apparently bending to pressure from partner OEMs who continue to report customers continuing to demand Windows XP, Microsoft decided this morning to extend the availability of the older operating system series to the retail channel and to partners from January to June 2008, as it maintains availability to system builders clear through to January 2009.</b></p><p>The move comes several months after Dell reported it would continue offering Windows XP as an option for its systems as long as it could. However, another possible contributing factor could be the companys plan for XP Service Pack 3. <a href="http://www.microsoft.com/windows/lifecycle/servicepacks.mspx" target="_blank">A check of the companys service pack roadmap</a> today shows the company has only tentative faith in its ability to produce SP3 by as late as next June.</p><p><div align=left style="float: left; margin-right: 8px;"> <iframe width="336" height="280" noresize scrolling="no" frameborder="0" marginheight="0" marginwidth="0" src="http://ad.doubleclick.net/adi/ttm.betanews/bn/article;tier=1;sz=336x280,300x250;tile=2;ord=935832037?"> <script language="JavaScript" src="http://ad.doubleclick.net/adj/ttm.betanews/bn/home;tier=1;sz=336x280,300x250;tile=2;ord=935832037?" type="text/javascript"></script> <noscript><a href="http://ad.doubleclick.net/jump/ttm.betanews/bn/home;tier=1;sz=336x280;tile=2;ord=935832037?" target="_blank"></a></noscript></iframe> </div><a href="http://www.microsoft.com/presspass/features/2007/sep07/09-27xpsalescycle.mspx" target="_blank">In a prepared Q&A for Microsoft this morning</a>, corporate vice president for Windows product management Mike Nash attempted to put the best spin he could on the move. He systematically eliminated the more obvious possible causes for his companys decision, leaving behind the option that Microsoft is just trying to be nice.</p><p>"While weve been pleased with the positive response weve seen and heard from customers using Windows Vista, there are some customers who need a little more time to make the switch to Windows Vista," said Nash in an attempt to sound comforting. </p><p>"As it turns out, our official policy as of 2002 is that versions of Windows are available through our retail and direct OEM partners for four years after they ship. Obviously this policy didnt work with Windows XP given Windows Vistas delivery date. As a practical matter, most of our previous operating system releases were available for about two years after the new version shipped, so maybe we were a little ambitious to think that we would need to make Windows XP available for only a year after the release of Windows Vista."</p><p>Other than its mild chastisement of customers for procrastinating on its otherwise well-tuned roadmap, Nashs discussion read today less like an explanation of XPs extended life and more like a pep talk for Vista. He said there are twice as many PCs being sold on an annual basis now than at the time XP was first introduced, and that a great many of those units - by virtue of the declining scale of costs - are low-price systems. For those systems, it appears, customers may be perceiving XP as the preferable choice.</p><p>But thats just a temporary setback, it appears, as Nash promises to be more sensitive to how customers needs evolve, as though the act of evolution itself were a postponement of the inevitable.</p><p>"Its early days still, but if things continue as were expecting, Windows Vista will be the fastest selling operating system in our history," reported Nash.</p><p>"And while thats gratifying on one level when you consider all the architectural changes we introduced, it also suggests weve done a lot of things right in delivering value to our customers. But we want to be sensitive to how our customers needs and experiences continue to evolve, so well continue to listen and look at how we can help our customers through the transition to Windows Vista."</p> </span> </div> http://www.betanews.com/article/Five_More_Months_Tacked_Onto_XP_Availability_Roadmap/1191000683 '; $html= preg_replace('/<[^>]*>/i', '', $html); $html= str_replace('','',$html); echo nl2br($html); ?> outputs lots of line breaks so I want to replace all the multiple line breaks with single or double line breaks only. Quote Link to comment https://forums.phpfreaks.com/topic/71432-validating-html-tags/#findComment-359865 Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 Try this <?php $html = '<head> <body onload="test();"> <b>testing</b> </body> '; $html= preg_replace('/<[^>]*>/i', '', $html); $html= preg_replace('/(\r\n){2,}/i', '\r\n', $html);//ADDED echo nl2br($html); ?> Quote Link to comment https://forums.phpfreaks.com/topic/71432-validating-html-tags/#findComment-359871 Share on other sites More sharing options...
prakash Posted October 2, 2007 Author Share Posted October 2, 2007 hi the above code outputs \r\ntesting\r\n I think it should output line breaks like testing while using nl2br Quote Link to comment https://forums.phpfreaks.com/topic/71432-validating-html-tags/#findComment-359873 Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 humm.. you could probably get away with this! <?php $html = '<head> <body onload="test();"> <b>testing</b> </body> '; $html= preg_replace('/<[^>]*>/i', '', $html); $html= preg_replace('/(\n){2,}/i', '<br>', $html);//updated //line removed echo $html; ?> Quote Link to comment https://forums.phpfreaks.com/topic/71432-validating-html-tags/#findComment-359876 Share on other sites More sharing options...
prakash Posted October 2, 2007 Author Share Posted October 2, 2007 but this is not producing any breaks all text is displaying on single line <?php $html = '<head> <body onload="test();"> <b>testing</b> </body> Some Text Some Text Some Text Some Text '; $html= preg_replace('/<[^>]*>/i', '', $html); $html= preg_replace('/(\n){2,}/i', '<br>', $html);//updated //line removed echo $html; ?> Quote Link to comment https://forums.phpfreaks.com/topic/71432-validating-html-tags/#findComment-359877 Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 displays fine on mine! <br>testing<br>Some Text<br>Some Text Some Text<br>Some Text<br> try changing to $html= preg_replace('/(\r|\n|\r\n){2,}/i', '\1', $html); Quote Link to comment https://forums.phpfreaks.com/topic/71432-validating-html-tags/#findComment-359901 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.