selective replacements

selective replacements

am 12.11.2005 09:33:05 von meltedown

I have this in one of my php scripts to take out line breaks:
$html=str_replace(array("\n","\r"),"",$html);

Now I would like to leave some line breaks.
For example, if $html has something like this:
""
I would like to leave all the linebreaks between the "
> I would like to leave all the linebreaks between the "
>>I would like to leave all the linebreaks between the "
>>>I would like to leave all the linebreaks between the
but you're free to google
them for yourself
STR

my $done;
$string =~ s#(.*?)(]*>.*?)?#my $txtarea=$2;(my $text
= $1)=~s/\n//;$done .="$text$txtarea"#gise;
print $done;

If you can't see why it's an abuse of the /e modifier then I wish you all
the luck in your programming future!

Matt

Re: selective replacements

am 12.11.2005 22:36:54 von meltedown

Matt Garrish wrote:
> "meltedown" wrote in message
> news:Neqdf.19659$Ww6.10326@fe05.news.easynews.com...
>
>>Matt Garrish wrote:
>>
>>>"meltedown" wrote in message
>>>news:5Nhdf.12304$Ur3.9768@fe01.news.easynews.com...
>>>
>>>
>>>>I have this in one of my php scripts to take out line breaks:
>>>> $html=str_replace(array("\n","\r"),"",$html);
>>>>
>>>>Now I would like to leave some line breaks.
>>>>For example, if $html has something like this:
>>>>""
>>>>I would like to leave all the linebreaks between the
> but you're free to google
> them for yourself
> STR
>
> my $done;
> $string =~ s#(.*?)(]*>.*?)?#my $txtarea=$2;(my $text
> = $1)=~s/\n//;$done .="$text$txtarea"#gise;
> print $done;
>

Thanks, but isn't there supposed to be a semi colon after
$string =~ s#(.*?)(]*>.*?)?#

Is that a typo or is that supposed to be like that ?
I'm just trying to make sure I understand it right.

> If you can't see why it's an abuse of the /e modifier then I wish you all
> the luck in your programming future!
>
> Matt
>
>

Re: selective replacements

am 12.11.2005 23:40:14 von Matt Garrish

"meltedown" wrote in message
news:Wftdf.30220$xl1.27689@fe03.news.easynews.com...
> Matt Garrish wrote:
>> "meltedown" wrote in message
>> news:Neqdf.19659$Ww6.10326@fe05.news.easynews.com...
>>
>>>Matt Garrish wrote:
>>>
>>>>"meltedown" wrote in message
>>>>news:5Nhdf.12304$Ur3.9768@fe01.news.easynews.com...
>>>>
>>>>
>>>>>I have this in one of my php scripts to take out line breaks:
>>>>> $html=str_replace(array("\n","\r"),"",$html);
>>>>>
>>>>>Now I would like to leave some line breaks.
>>>>>For example, if $html has something like this:
>>>>>""
>>>>>I would like to leave all the linebreaks between the
>> but you're free to google
>> them for yourself
>> STR
>>
>> my $done;
>> $string =~ s#(.*?)(]*>.*?)?#my $txtarea=$2;(my
>> $text = $1)=~s/\n//;$done .="$text$txtarea"#gise;
>> print $done;
>>
>
> Thanks, but isn't there supposed to be a semi colon after
> $string =~ s#(.*?)(]*>.*?)?#
>
> Is that a typo or is that supposed to be like that ?
> I'm just trying to make sure I understand it right.
>

No. Look up the /e switch in perlre.

Matt

Re: selective replacements

am 13.11.2005 07:39:18 von meltedown

Matt Garrish wrote:
> "meltedown" wrote in message
> news:Wftdf.30220$xl1.27689@fe03.news.easynews.com...
>
>>Matt Garrish wrote:
>>
>>>"meltedown" wrote in message
>>>news:Neqdf.19659$Ww6.10326@fe05.news.easynews.com...
>>>
>>>
>>>>Matt Garrish wrote:
>>>>
>>>>
>>>>>"meltedown" wrote in message
>>>>>news:5Nhdf.12304$Ur3.9768@fe01.news.easynews.com...
>>>>>
>>>>>
>>>>>
>>>>>>I have this in one of my php scripts to take out line breaks:
>>>>>>$html=str_replace(array("\n","\r"),"",$html);
>>>>>>
>>>>>>Now I would like to leave some line breaks.
>>>>>>For example, if $html has something like this:
>>>>>>""
>>>>>>I would like to leave all the linebreaks between the
>>>but you're free to google
>>>them for yourself
>>>STR
>>>
>>>my $done;
>>>$string =~ s#(.*?)(]*>.*?)?#my $txtarea=$2;(my
>>>$text = $1)=~s/\n//;$done .="$text$txtarea"#gise;
>>>print $done;
>>>
>>
>>Thanks, but isn't there supposed to be a semi colon after
>>$string =~ s#(.*?)(]*>.*?)?#
>>
>>Is that a typo or is that supposed to be like that ?
>>I'm just trying to make sure I understand it right.
>>
>
>
> No. Look up the /e switch in perlre.
>
> Matt
>
>
Ok. Thanks for clarifying. You've given me an idea by suggesting a
parser. I do have my own html parser and I think I can adjust it so
instead of just taking out all the linebreaks, it takes them out on a
tag by tag basis.

Re: selective replacements

am 18.11.2005 21:44:35 von Jim Gibson

In article , meltedown
wrote:

> Matt Garrish wrote:
> > "meltedown" wrote in message
> > news:Neqdf.19659$Ww6.10326@fe05.news.easynews.com...
> >

[problem description snipped]

> > The following is hack that will do what
> > you want, but hopefully will give you an idea about why you need to do more
> > than write a simple regular expression. (watch for wrapping on the regex)
> >
> > my $string = < > > php is no perl
> >
> > but you're free to google
> > them for yourself
> > STR
> >
> > my $done;
> > $string =~ s#(.*?)(]*>.*?)?#my $txtarea=$2;(my $text
> > = $1)=~s/\n//;$done .="$text$txtarea"#gise;
> > print $done;
> >
>
> Thanks, but isn't there supposed to be a semi colon after
> $string =~ s#(.*?)(]*>.*?)?#
>

No. The s#...# is the first part of the substitution operator, written
by Matt to use # as a delimiter: s#...#...#gise;
The entire statement is in two lines:

$string =~ s#...#...
....#gise;

> Is that a typo or is that supposed to be like that ?
> I'm just trying to make sure I understand it right.

Did it work when you tried it? Did you get a compile error when you
added a semicolon?

>
> > If you can't see why it's an abuse of the /e modifier then I wish you all
> > the luck in your programming future!
> >
> > Matt

I am leaving Matt's good advice in my response.

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com