Current location: Hot Scripts Forums » General Web Coding » JavaScript » delete part of string just a few times


delete part of string just a few times

Reply
  #1 (permalink)  
Old 06-17-09, 06:16 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 704
Thanks: 0
Thanked 0 Times in 0 Posts
delete part of string just a few times

Hi there,

I'm trying a new wysiwyg editor... (Wyzz WYSIWYG Editor)

this editor add on my mac a "<br>" at the end of the
text in the text area each time it's saved.

Is there an easy way to remove each "<br>" at the end
from a string (sometimes there are more after saving multiple times)..

The other "<br>" used in the text shoud remain.

_j
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-17-09, 06:31 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
You could try to trim() the string before it's being processed.

Otherwise, you could use preg_replace() with the limit parameter.

PHP: preg_replace - Manual
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-17-09, 06:39 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 704
Thanks: 0
Thanked 0 Times in 0 Posts
the preg_replace is not working I guess...
because the number of "<br>" is variable..

and I did trim() the string...

on IE there is no problem at all..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 06-17-09, 06:42 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
If the <br> appears at the end of the string, it should work? If there's one, it'll be replaced, and if not, then nothing is replaced.

PHP Code:

'~(<br\s*/?>)+$~i' 

... (this would remove all <br> tags from the end of the string. Untested but should work)

Last edited by Nico; 06-17-09 at 06:44 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 06-17-09, 06:44 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 704
Thanks: 0
Thanked 0 Times in 0 Posts
okay... I'll give this a try.. sorry for the doubt..

what if there are more the one?.. only the last is replaced? or can
I make it a kind of loop the runs untill there is no <br> at the end?.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 06-17-09, 06:45 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
I edited my post above before I read your reply. I fixed that issue (at least I think I did).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 06-17-09, 08:01 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 704
Thanks: 0
Thanked 0 Times in 0 Posts
EDIT: I inserted html_entity_decode() to escape the following...


hmzz... as I look into the DB where it's stored the <br> is written as "&lt;br>" can that infect the preg_replace as you gave me above?.

Last edited by jonnekke; 06-17-09 at 08:21 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
OOP C-Sharp DB Access Wrapper Question digioz ASP.NET 1 09-08-08 10:54 AM
search function using dot net nishudude_13 Windows .NET Programming 1 08-28-08 12:28 PM
[SOLVED] searching through a grid view painthu ASP.NET 5 05-21-08 11:11 AM
Declared Functions skipper23 PHP 4 12-17-03 11:06 AM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM


All times are GMT -5. The time now is 08:29 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.