PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old August 11th, 2002, 01:27 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
one preg_replace

I need one preg_replace function to replace "rn" with "<br>" except "rn" that beetween [textarea] and [/textarea]


Reply With Quote
  #2  
Old August 11th, 2002, 02:02 AM
Gipz Gipz is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Stockholm, Sweden
Posts: 98 Gipz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Gipz
RE: one preg_replace


you have looked at the nl2br() function?

Reply With Quote
  #3  
Old August 12th, 2002, 02:31 AM
Kohaar Kohaar is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Denmark
Posts: 147 Kohaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 37 sec
Reputation Power: 2
Send a message via ICQ to Kohaar
RE: one preg_replace

Hmm.. I'm not that great with regular expressions, but I've come up with this:

php Code:
Original - php Code
  1.  
  2. <php
  3.  
  4. $document = preg_replace ("'(<textarea[^>]*?>.*?)rn(.*?</textarea>)'si", "\1<!--new-->\2", $document);
  5. $document = preg_replace ("'rn'", "<br>", $document);
  6. $document = preg_replace ("'<!--new-->'", "rn", $document);
  7.  
  8. ?>


My problem is, that if rn appears more than once in <textarea></textarea> it is turned into <br>. I can’t seem to find the solution to this. Anyone?

Reply With Quote
  #4  
Old August 12th, 2002, 05:47 PM
Kohaar Kohaar is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Denmark
Posts: 147 Kohaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 37 sec
Reputation Power: 2
Send a message via ICQ to Kohaar
RE: one preg_replace

Is ereryone just as bad as I am at this

Reply With Quote
  #5  
Old August 12th, 2002, 09:07 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: one preg_replace

woooo this was fun.. i think i acheived what you want using a whole bunch of str_replace functions lol. i didn't test it though, i'm sure you'll come up with a more better way anyhow

php Code:
Original - php Code
  1.  
  2. <?php
  3.  
  4. $string = "here is rn some b.s. data rn [textarea]hello rn there[/textarea] rn !";
  5.  
  6. $string = str_replace("rn", "<br>", $string);
  7.  
  8. $begin_crop = strstr($string, "[textarea]");
  9. $end_crop = strstr($begin_crop, "[/textarea]");
  10. $begin_crop = str_replace($end_crop, "[/textarea]", $begin_crop);
  11.  
  12. $new_crop = str_replace("<br>", "rn", $begin_crop);
  13.  
  14. $string = str_replace($begin_crop, $new_crop, $string);
  15.  
  16. print("$string");
  17.  
  18. ?>

Reply With Quote
  #6  
Old August 13th, 2002, 12:36 AM
Kohaar Kohaar is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Denmark
Posts: 147 Kohaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 37 sec
Reputation Power: 2
Send a message via ICQ to Kohaar
RE: one preg_replace

Hehe... Nice job... Only problem is if he meant <textarea> instead of [textarea]. Then you have to take something like <textarea cols="9"...> in consideration...

Reply With Quote
  #7  
Old August 13th, 2002, 12:56 AM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: one preg_replace

yah plus MULTIPLE textarea's within one string..

Reply With Quote
  #8  
Old August 13th, 2002, 01:00 AM
Kohaar Kohaar is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Denmark
Posts: 147 Kohaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 37 sec
Reputation Power: 2
Send a message via ICQ to Kohaar
RE: one preg_replace

yep... Would still like to see it in a regular expression. Maybe I could learn somthing :-)

Reply With Quote
  #9  
Old August 13th, 2002, 09:28 AM
Gipz Gipz is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Stockholm, Sweden
Posts: 98 Gipz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Gipz
RE: one preg_replace

This matches the textareas with attributes:
php Code:
Original - php Code
  1.  
  2. <?php
  3. $randomStr = '<body><br><br><form action="ftp://"><textarea class="test" cols="test">hej this is <br>an area <br> sddf</textarea></form><br></body>';
  4. $matches = array();
  5. preg_match('/<textarea*?[^<>]*?>(.*?)</textarea>/mi', $randomStr, $matches);
  6.  
  7. var_dump($matches); // result in $matches[1]
  8. ?>

Reply With Quote
  #10  
Old August 13th, 2002, 11:50 AM
Kohaar Kohaar is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Denmark
Posts: 147 Kohaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 37 sec
Reputation Power: 2
Send a message via ICQ to Kohaar
RE: one preg_replace

Yep... Almost the same as mine in post 3... Still need a regular expresion that replaces rn with <br> outside textarea...

Reply With Quote
  #11  
Old August 13th, 2002, 11:50 AM
Kohaar Kohaar is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Denmark
Posts: 147 Kohaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 37 sec
Reputation Power: 2
Send a message via ICQ to Kohaar
RE: one preg_replace

Yep... Almost the same as mine in post 3... Still need a regular expresion that replaces rn with <br> outside textarea...

Reply With Quote
  #12  
Old August 13th, 2002, 12:34 PM
Kohaar Kohaar is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Denmark
Posts: 147 Kohaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 37 sec
Reputation Power: 2
Send a message via ICQ to Kohaar
RE: one preg_replace

Hmm.. Strange

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > one preg_replace


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |