RE: [PHP] ereg() violence
| From: | WILSON, Nick | Date: | Wed, 08 Nov 2000 05:11:38 +0000 |
| Subject: | RE: [PHP] ereg() violence | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-24266@lists.php.net to get a copy of this message | ||
Here's a function that I found to strip text, you might need to get rid of
the entry for html tags, and then do a preg_replace on some href stuff.
function _striptext($document)
{
// I didn't use preg eval (//e) since that is only available
in PHP 4.0.
// so, list your entities one by one here. I included some
of the
// more common ones.
$search = array("'<script[^>]*?>.*?</script>'si", //
strip out javascript
"'<[\/\!]*?[^<>]*?>'si",
// strip out html tags
"'([\r\n])[\s]+'",
// strip out white space
"'&(quote|#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"
);
$replace = array( "",
"",
"\\1",
"\"",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169));
$text = preg_replace($search,$replace,$document);
return $text;
}
> -----Original Message-----
> From: Jesse Binam [mailto:sirbinam@xmission.com]
> Sent: Wednesday, 8 November 2000 15:51
> To: Maxim Maletsky; php-general@lists.php.net
> Subject: Re: [PHP] ereg() violence
>
>
> Maxim -
>
> I appreciate your feedback.
> my understanding of this thusfar is that it turns html tags
> into text by
> replacing characters like < with >
> Am I wrong?
>
> What I am doing is making a mailing list app. When the author
> write the
> message they will choose whether
> the message is text or html. If it is text it sends it out.
> If it is html it
> needs to make a text version of the page to
> send to the members of the list that have requested text only
> messages. So I
> wouldn't want to change < to >
> I want to change this:
>
> <font color="FF0000" face="Verdana">HELLO WORLD & OTHER
> PEOPLE</font><br>
> <br>
> <img src="image.jpg">
>
> into this:
>
> HELLO WORLD & OTHER PEOPLE
>
> <<image.jpg>>
>
> This is should be so easy. I would have thought that there would be an
> html2text() function or something to
> do this. I am sure that other people have done this I just
> can't find any
> other programs that do this.
>
> Jess
>
>
> ----- Original Message -----
> From: Maxim Maletsky <maxim.maletsky@japaninc.net>
> To: 'Jesse Binam' <sirbinam@xmission.com>; <php-general@lists.php.net>
> Sent: Tuesday, November 07, 2000 9:19 PM
> Subject: RE: [PHP] ereg() violence
>
>
> > You can use HTML_ENTITIES,
> >
> > $trans = get_html_translation_table(HTML_ENTITIES);
> > $trans[" "] = " ";
> > $html = strtr($original, $trans);
> >
> > this will transform every HTML-looking tag into the format
> that you can
> see
> > on a vebsite,
> >
> > then you adding and adding
> > ereg()
> > # after
> > ereg()
> >
> > can fix other issues..
> >
> > Cheers
> >
> >
> > -----Original Message-----
> > From: Jesse Binam [mailto:sirbinam@xmission.com]
> > Sent: Wednesday, November 08, 2000 1:10 PM
> > To: php-general@lists.php.net
> > Subject: [PHP] ereg() violence
> >
> >
> > I have been screwing with this thing for 7 hours and CANNOT
> get it to
> work.
> >
> > When the author submits an html message the script needs to:
> > replace tags like <br>, <p>, <div> with \n
> > replace HTML codes with text equivelent like & with &
> > strip all other HTML tags that have no place in a text
> message like <b>,
> > <font>, etc.
> > and it would be nice if it would find the img tags and
> replace them with
> > something like
> > <<http://www.isp.com/images/pic.jpg>>
> >
> > But I am running into some serious problems!!
> > Either I can't get the regular expression right or it times
> out (possibly
> > because the regular expression is wrong)
> > I just don't know what to do. I think it would increase
> performance IF I
> > could somehow code it to replace only
> > what is there instead of searching for a every possible
> code whether it is
> > there or not.
> >
> > Suggestions on this would be GREATLY appreciated
> >
> > Jess
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail:
> php-list-admin@lists.php.net
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail:
> php-list-admin@lists.php.net
> >
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail:
> php-list-admin@lists.php.net
>
>