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
Re: selective replacements
am 12.11.2005 17:18:10 von Matt Garrish
"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
Re: selective replacements
am 12.11.2005 19:10:53 von meltedown
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
Re: selective replacements
am 12.11.2005 20:12:14 von Matt Garrish
"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
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:
>>>>" default text\n with line \nbreaks "
>>>>I would like to leave all the linebreaks between the tags.
>>>>Does any one know of a regular expression that can do this ?
>>>
>>>
>>>alt.php is down the hall...
>>>
>>
>>Don't be nervous just because I mentioned PHP. I'm looking for a regular
>>expression, and if its in a perl context, that's fine. I can just as
>>easily use it in PHP. Perhaps you don't know this, but the syntax of
>>regular expressions in PHP is almost identical to that of perl. The people
>>in this newgroup are much much better at regular expressions than the
>>people in the PHP group, and they do not have an answer to this question.
>>I've already tried.
>>
>>How do I replace all the line breaks in a string with '', except the line
>>breaks between tags ? There's nothing unperl about that
>>question.
>
>
> The reason I refused to answer has nothing to do with anything you note
> above, but that you should be using a parser and not a regular expression
> (and for that you should be using the functionality provided by PHP and not
> asking for help in a Perl group).
> 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
> for reasons
> that are too complicated
> to explain here
> 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:
>>>>>" default text\n with line \nbreaks "
>>>>>I would like to leave all the linebreaks between the tags.
>>>>>Does any one know of a regular expression that can do this ?
>>>>
>>>>
>>>>alt.php is down the hall...
>>>>
>>>
>>>Don't be nervous just because I mentioned PHP. I'm looking for a regular
>>>expression, and if its in a perl context, that's fine. I can just as
>>>easily use it in PHP. Perhaps you don't know this, but the syntax of
>>>regular expressions in PHP is almost identical to that of perl. The
>>>people in this newgroup are much much better at regular expressions than
>>>the people in the PHP group, and they do not have an answer to this
>>>question. I've already tried.
>>>
>>>How do I replace all the line breaks in a string with '', except the
>>>line breaks between tags ? There's nothing unperl about that
>>>question.
>>
>>
>> The reason I refused to answer has nothing to do with anything you note
>> above, but that you should be using a parser and not a regular expression
>> (and for that you should be using the functionality provided by PHP and
>> not asking for help in a Perl group).
>
>> 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
>> for reasons
>> that are too complicated
>> to explain here
>> 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:
>>>>>>" default text\n with line \nbreaks "
>>>>>>I would like to leave all the linebreaks between the tags.
>>>>>>Does any one know of a regular expression that can do this ?
>>>>>
>>>>>
>>>>>alt.php is down the hall...
>>>>>
>>>>
>>>>Don't be nervous just because I mentioned PHP. I'm looking for a regular
>>>>expression, and if its in a perl context, that's fine. I can just as
>>>>easily use it in PHP. Perhaps you don't know this, but the syntax of
>>>>regular expressions in PHP is almost identical to that of perl. The
>>>>people in this newgroup are much much better at regular expressions than
>>>>the people in the PHP group, and they do not have an answer to this
>>>>question. I've already tried.
>>>>
>>>>How do I replace all the line breaks in a string with '', except the
>>>>line breaks between tags ? There's nothing unperl about that
>>>>question.
>>>
>>>
>>>The reason I refused to answer has nothing to do with anything you note
>>>above, but that you should be using a parser and not a regular expression
>>>(and for that you should be using the functionality provided by PHP and
>>>not asking for help in a Perl group).
>>
>>>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
>>>for reasons
>>>that are too complicated
>>>to explain here
>>>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
> > for reasons
> > that are too complicated
> > to explain here
> > 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