Reply
Remove dynamic content from a string...
Old 03-04-2008, 03:36 PM Remove dynamic content from a string...
Skilled Talker

Posts: 61
I'm making a comments system and I'm adding a BBCode quote system.

It works great for one quote, but if you try to quote a quote it messes up. I would rather there only be one quote. So, I want a function to remove [ quote]quoted message[/ quote] when it adds the quote tags.

This is hard to explain, I hope you get what I mean.

Here's is my function to add the quote tags in the first place:

Code:
function addQuote(user,quote) {
    var newtext ="[ quote="+user+"]"+quote+"[/ quote]";
    document.post.post_body.value += newtext;
}
And my usage:

Code:
<a href="javascript:addQuote(\''.$userRow['username'].'\',\''.$cRow['comments_body'].'\');">Quote</a
Works great. But, like I said, I need the function to strip anything between the quote tags before it's quoted... if that makes any sense at all....

I was thinking I'd have to use regex, but I'm only a newbie with Javascript and that looks intimidating. I'm good at modifying existing code, so if anyone use a tutorial that glances at what I'm trying to do that'd be great too.

Thanks.

EDIT: Hmm, I have to put spaces in my function above because it messed up the forum's quotes, lol.

Last edited by CrazeDizzleD : 03-04-2008 at 03:39 PM.
CrazeDizzleD is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 03-04-2008, 08:22 PM Re: Remove dynamic content from a string...
vangogh's Avatar
Post Impressionist

Posts: 8,935
Name: Steven Bradley
Location: Boulder, Colorado
Try using a string.replace on the variable quote before using quote in newText

quote = quote.replace(/"/g, '');
var newText = ...

I think that will work
__________________
l Search Engine Friendly Web Design | Van SEO Design
l Tips On Marketing, SEO, Design, and Development | TheVanBlog
l Custom WordPress Themes
| Small Business Forum
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 03-04-2008, 09:39 PM Re: Remove dynamic content from a string...
Skilled Talker

Posts: 61
No, that's not what I was looking for.

Maybe I didn't explain it well enough.

Person 1 says "hey, cool site".

Person 2 quotes him and says "yeah, it is cool"

So in Person 2's post, you'd have the quote tags with "hey, cool site" and then under that, "yeah, it is cool".

Then Person 3 comes along and quotes Person 2, and says "I don't like it".

Now Person 3's post has the quote from Person 1 AND Person 2. I want it to only have what Person 2 said.

How can I do this?
CrazeDizzleD is offline
Reply With Quote
View Public Profile
 
Old 03-04-2008, 10:37 PM Re: Remove dynamic content from a string...
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Converting Video For YouTube
Posts: 2,339
Name: Keith Marshall
Location: West Hartford, CT
This is untested, but will this work for you?

Code:
function addQuote(user,quote) {
    quote = quote.replace(/\[ quote.*\]\w*\[\/quote\]\n*/g, '');
    var newtext = '[ quote="+user+"]"+quote+"[/ quote]';
    document.post.post_body.value += newtext;
}
__________________

<mgraphic /> - I don't have a solution but I admire the problem.

Last edited by mgraphic : 03-04-2008 at 10:38 PM.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-04-2008, 10:45 PM Re: Remove dynamic content from a string...
Skilled Talker

Posts: 61
No, that doesn't do anything.
CrazeDizzleD is offline
Reply With Quote
View Public Profile
 
Old 03-04-2008, 10:52 PM Re: Remove dynamic content from a string...
vangogh's Avatar
Post Impressionist

Posts: 8,935
Name: Steven Bradley
Location: Boulder, Colorado
Oops. I completely misunderstood before. It sounds like you need to hold two variables instead of just the single quote. One holds the previous quote and one holds the new text.

Person 2 quotes person 1. Person 1's text goes in quote and person 2's text goes into new text. Then you have another variable putting them together and displaying them how you want.

When person 3 comes along and quotes person 2 you take the new text variable from person 2's post and move that to the quote variable and person 3's text now replaces what was in the new text variable.

So instead of quote and newText you have quote, newText, combinationText.
__________________
l Search Engine Friendly Web Design | Van SEO Design
l Tips On Marketing, SEO, Design, and Development | TheVanBlog
l Custom WordPress Themes
| Small Business Forum
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 03-04-2008, 11:17 PM Re: Remove dynamic content from a string...
Skilled Talker

Posts: 61
No, you still misunderstand.

It has to be completely dynamic, for one. All this function is doing is copying a post into the comment post box and putting quote tags on it. The rest is with PHP.

All I need to do is filter any existing quotes out of the post before it is copied over.

IE: If you quote a post that looks like this:

"[ quote]cool site[ /quote]

Yeah it is"

It turns into:

"Yeah it is"

mgraphic has the right idea, but unfortunately that didn't work.
CrazeDizzleD is offline
Reply With Quote
View Public Profile
 
Old 03-04-2008, 11:29 PM Re: Remove dynamic content from a string...
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Converting Video For YouTube
Posts: 2,339
Name: Keith Marshall
Location: West Hartford, CT
Code:
function addQuote(user,quote) {
    quote = quote.replace(/\[ quote.*quote\]/g, '');
    var newtext = '[ quote='+user+']'+quote+'[/quote]';
    document.post.post_body.value += newtext;
}
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-04-2008, 11:53 PM Re: Remove dynamic content from a string...
Skilled Talker

Posts: 61
WORKED!

Thanks a lot!
CrazeDizzleD is offline
Reply With Quote
View Public Profile
 
Old 03-04-2008, 11:54 PM Re: Remove dynamic content from a string...
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Converting Video For YouTube
Posts: 2,339
Name: Keith Marshall
Location: West Hartford, CT
That time I tested
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-05-2008, 06:26 PM Re: Remove dynamic content from a string...
vangogh's Avatar
Post Impressionist

Posts: 8,935
Name: Steven Bradley
Location: Boulder, Colorado
Too late, but I finally understand what you wanted. Sorry about that. Glad Keith was able to help.
__________________
l Search Engine Friendly Web Design | Van SEO Design
l Tips On Marketing, SEO, Design, and Development | TheVanBlog
l Custom WordPress Themes
| Small Business Forum
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Reply     « Reply to Remove dynamic content from a string...
 

Thread Tools

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15656 seconds with 12 queries