[pLog-svn] r3433 - plog/trunk/class/view/admin

Mark Wu markplace at gmail.com
Thu May 18 11:40:02 GMT 2006


Here comes the example from php.net.

Maybe we can refer to this write our own replacement.

Mark

===========

Example 1. Convert HTML to text

<?php
// $document should contain an HTML document.
// This will remove HTML tags, javascript sections
// and white space. It will also convert some
// common HTML entities to their text equivalent.
$search = array ('@<script[^>]*?>.*?</script>@si', // Strip out javascript
                 '@<[\/\!]*?[^<>]*?>@si',          // Strip out HTML tags
                 '@([\r\n])[\s]+@',                // Strip out white space
                 '@&(quot|#34);@i',                // Replace HTML entities
                 '@&(amp|#38);@i',
                 '@&(lt|#60);@i',
                 '@&(gt|#62);@i',
                 '@&(nbsp|#160);@i',
                 '@&(iexcl|#161);@i',
                 '@&(cent|#162);@i',
                 '@&(pound|#163);@i',
                 '@&(copy|#169);@i',
                 '@&#(\d+);@e');                    // evaluate as php

$replace = array ('',
                 '',
                 '\1',
                 '"',
                 '&',
                 '<',
                 '>',
                 ' ',
                 chr(161),
                 chr(162),
                 chr(163),
                 chr(169),
                 'chr(\1)');

$text = preg_replace($search, $replace, $document);
?> 
 
 

> -----Original Message-----
> From: plog-svn-bounces at devel.lifetype.net 
> [mailto:plog-svn-bounces at devel.lifetype.net] On Behalf Of Jon Daley
> Sent: Thursday, May 18, 2006 7:27 PM
> To: plog-svn at devel.lifetype.net
> Subject: Re: [pLog-svn] r3433 - plog/trunk/class/view/admin
> 
>  	This looks really bizarre?  You are trying to replace & 
> with &amp; only if it isn't already &amp;?  There must be a 
> better way to do that.
> 
> Also, perhaps you really want to replace a & if it isn't 
> followed by "[a-z0-9]+;" to cover all cases of escaped html?
> 
> 
> On Thu, 18 May 2006, mark at devel.lifetype.net wrote:
> > Author: mark
> > Date: 2006-05-18 10:46:03 +0000 (Thu, 18 May 2006)
> > New Revision: 3433
> >
> > Modified:
> >   plog/trunk/class/view/admin/admineditpostview.class.php
> > Log:
> > Fixed the bug here: http://bugs.lifetype.net/view.php?id=896
> >
> > Modified: plog/trunk/class/view/admin/admineditpostview.class.php
> > ===================================================================
> > --- plog/trunk/class/view/admin/admineditpostview.class.php	
> 2006-05-18 10:41:43 UTC (rev 3432)
> > +++ plog/trunk/class/view/admin/admineditpostview.class.php	
> 2006-05-18 10:46:03 UTC (rev 3433)
> > @@ -50,8 +50,8 @@
> >
> > 	            // set information about the post itself 
> into the view
> > 	            $this->setValue( "postTopic", 
> $this->_article->getTopic());
> > -	            $this->setValue( "postText", 
> preg_replace('/&/', '&amp;', $this->_article->getIntroText()));
> > -	            $this->setValue( "postExtendedText", 
> preg_replace('/&/','&amp;',$this->_article->getExtendedText()));
> > +	            $this->setValue( "postText", 
> preg_replace('/(&amp;|&)/', '&amp;', 
> $this->_article->getIntroText()));
> > +	            $this->setValue( "postExtendedText", 
> preg_replace('/(&amp;|&)/','&amp;',$this->_article->getExtende
> dText()));
> > 	            $this->setValue( "postSlug", 
> $this->_article->getPostSlug());
> > 	            $this->setValue( "postId", 
> $this->_article->getId());
> > 	            if( $this->_article->getCommentsEnabled())
> >
> > _______________________________________________
> > pLog-svn mailing list
> > pLog-svn at devel.lifetype.net
> > http://devel.lifetype.net/mailman/listinfo/plog-svn
> >
> 
> **************************************
> Jon Daley
> http://jon.limedaley.com/
> 
> The difference between genius and stupidity
> is that genius has its limits.
> -- Anonymous
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.lifetype.net
> http://devel.lifetype.net/mailman/listinfo/plog-svn



More information about the pLog-svn mailing list