preg_replace driving me nuts!

This is a discussion on preg_replace driving me nuts! within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I've got code to blindly remove '<.*?>' from email messages. It works if I dump the message to ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-28-2004
Greg Brondo
 
Posts: n/a
Default preg_replace driving me nuts!

I've got code to blindly remove '<.*?>' from email messages. It works if I
dump the message to a file and then read it in. If I just work on the block
of text directly it doesn't work. Anyone experienced this before? It's
nerve wracking!

Greg B.


Reply With Quote
  #2 (permalink)  
Old 01-29-2004
Tim Van Wassenhove
 
Posts: n/a
Default Re: preg_replace driving me nuts!

On 2004-01-28, Greg Brondo <greg@brondo.com> wrote:
> I've got code to blindly remove '<.*?>' from email messages. It works if I
> dump the message to a file and then read it in. If I just work on the block
> of text directly it doesn't work. Anyone experienced this before? It's
> nerve wracking!


Provide us with the lines in your code where you have the pattern
matching, so we can have a look at it.

--
http://home.mysth.be/~timvw
Reply With Quote
  #3 (permalink)  
Old 01-29-2004
Tim Van Wassenhove
 
Posts: n/a
Default Re: preg_replace driving me nuts!

On 2004-01-28, Greg Brondo <greg@brondo.com> wrote:
> I've got code to blindly remove '<.*?>' from email messages. It works if I
> dump the message to a file and then read it in. If I just work on the block
> of text directly it doesn't work. Anyone experienced this before? It's
> nerve wracking!


If you use output buffering, you could run tidy on the contents of the
page, and then output the lot.

--
http://home.mysth.be/~timvw
Reply With Quote
  #4 (permalink)  
Old 01-30-2004
Greg Brondo
 
Posts: n/a
Default Re: preg_replace driving me nuts!

function get_stripped_block () {

return preg_replace ("/<.*?>/", '', $this->get_block());

}


function get_block () {

$block = $this->from . "\n" . $this->subject . "\n" . $this->body;

return $block;

}



That's the two functions. What happens is it completey removes a block of
the text instead of replacing '<.*?>' with "". If I write the test to a
file and then read it back in and run the function above, it works
correctly. Could it be a end-of-line conversion that is triggering it?
Also, the functions work with other blocks of text and fails on others....
It's very odd.



Thanks!

Greg B.

"Tim Van Wassenhove" <euki@pi.be> wrote in message
news:bv9na1$pntv1$2@ID-188825.news.uni-berlin.de...
> On 2004-01-28, Greg Brondo <greg@brondo.com> wrote:
> > I've got code to blindly remove '<.*?>' from email messages. It works

if I
> > dump the message to a file and then read it in. If I just work on the

block
> > of text directly it doesn't work. Anyone experienced this before? It's
> > nerve wracking!

>
> Provide us with the lines in your code where you have the pattern
> matching, so we can have a look at it.
>
> --
> http://home.mysth.be/~timvw



Reply With Quote
  #5 (permalink)  
Old 01-30-2004
Cameron
 
Posts: n/a
Default Re: preg_replace driving me nuts!

Greg Brondo wrote:
> I've got code to blindly remove '<.*?>' from email messages. It works if I
> dump the message to a file and then read it in. If I just work on the block
> of text directly it doesn't work. Anyone experienced this before? It's
> nerve wracking!
>
> Greg B.
>
>


try changing your preg_replace pattern to

/<.*?>/s

I was having troubles with pregs, in my case the other way around, from
a file untill I added the s pattern modifier, not sure if this will
solve your problem, it's just a guess as I was having a very simaler one.

~Cameron
Reply With Quote
  #6 (permalink)  
Old 01-30-2004
Greg Brondo
 
Posts: n/a
Default Re: preg_replace driving me nuts!

Argh!!! I cannot believe I missed that! Thanks much!

Greg B.


"Cameron" <foo@bar.invalid> wrote in message
news:bve0eq$jdl$1@newsg3.svr.pol.co.uk...
> Greg Brondo wrote:
> > I've got code to blindly remove '<.*?>' from email messages. It works

if I
> > dump the message to a file and then read it in. If I just work on the

block
> > of text directly it doesn't work. Anyone experienced this before? It's
> > nerve wracking!
> >
> > Greg B.
> >
> >

>
> try changing your preg_replace pattern to
>
> /<.*?>/s
>
> I was having troubles with pregs, in my case the other way around, from
> a file untill I added the s pattern modifier, not sure if this will
> solve your problem, it's just a guess as I was having a very simaler one.
>
> ~Cameron



Reply With Quote
  #7 (permalink)  
Old 01-30-2004
Cameron
 
Posts: n/a
Default Re: preg_replace driving me nuts!

Greg Brondo wrote:
> Argh!!! I cannot believe I missed that! Thanks much!
>
> Greg B.
>
>
> "Cameron" <foo@bar.invalid> wrote in message
> news:bve0eq$jdl$1@newsg3.svr.pol.co.uk...
>
>>Greg Brondo wrote:
>>
>>>I've got code to blindly remove '<.*?>' from email messages. It works

>
> if I
>
>>>dump the message to a file and then read it in. If I just work on the

>
> block
>
>>>of text directly it doesn't work. Anyone experienced this before? It's
>>>nerve wracking!
>>>
>>>Greg B.
>>>
>>>

>>
>>try changing your preg_replace pattern to
>>
>>/<.*?>/s
>>
>>I was having troubles with pregs, in my case the other way around, from
>>a file untill I added the s pattern modifier, not sure if this will
>>solve your problem, it's just a guess as I was having a very simaler one.
>>
>>~Cameron

>
>
>


*Grins* no problem, I know how regex's can be a PITA, oh and just a
little nit pick now I have been nice, if you could bottom post we would
appriciate it ;)

~Cameron
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:55 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0