Connecting Tech Pros Worldwide Help | Site Map

selective replacements

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 11th, 2005, 01:25 AM
meltedown
Guest
 
Posts: n/a
Default selective replacements

I have this in one of my 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:
"<textarea> default text\n with line \nbreaks </textarea>"
I would like to leave all the linebreaks between the <textarea> tags.
Does any one know of a script, or a regular expression that can do this ?

  #2  
Old November 11th, 2005, 06:45 PM
vizo
Guest
 
Posts: n/a
Default Re: selective replacements

it will be a big regex if you want to finish the job with only one reg
expression

i used this method :

1.replace the '\n' i want to keep with a strange char such as \0x23 one
by one
thus,the regex is easy to access

2.after replaced all '\n's should be kept, use '\r' to take place of
'\n' left
the '\n' left is really what you want to replace

3.turn our strange char(\0x23) back to '\n'

your should make several easy reg expressions,
but not a big big one.

hope help


Regards
vizo

meltedown wrote:[color=blue]
> I have this in one of my 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:
> "<textarea> default text\n with line \nbreaks </textarea>"
> I would like to leave all the linebreaks between the <textarea> tags.
> Does any one know of a script, or a regular expression that can do this ?[/color]
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.