Jump to content

Regex to prevent people to stop posting just "quotes"


Recommended Posts

I think I might be over-thinking this..

 

but let's say a user on my board decides to post

 

[quote=Fred]hello everyone[/quote]

 

Is there a way, I can check server side if no text or characters are used after "

"?

 

"Error!, You cannot post just a quote, you need to enter a post".

 

This is because I don't want peeps just posting with a quote, they should atleast reply/say something u know?

 

 

 

Or maybe instead of me just asking for help all the time I think a little? So that's what I did, my only solution would be to do something like this:

 

substr("[quote=Fred]hello everyone[/quote]", -1);

 

 

but this would only return "]", how can I make it return 7 more characters, so I can just check if "" is the last string used, and if it is, then error the user out! or do you think regex would be appropriate here? Which one is better for performance for large body of text, < 12,000 bytes (TEXT) MYSQL field??

 

 

 

 

 

 

I must confess that I'm disappointed that you didn't reference the PHP manual for substr () before posting this, the answer to your question is quite clearly defined in the examples there.

 

That said, you should probably want to use substr_count () in addition, to ensure that there is only one quote tag in the post. Also take into consideration those who start their posts with answering the quote, and then just leave the entire post quoted at the end.

I must confess that I'm disappointed that you didn't reference the PHP manual for substr () before posting this, the answer to your question is quite clearly defined in the examples there.

 

That said, you should probably want to use substr_count () in addition, to ensure that there is only one quote tag in the post. Also take into consideration those who start their posts with answering the quote, and then just leave the entire post quoted at the end.

 

BAM

 

substr('[quote=ROFL]hey ChristianF PPHPFREAKSz[/quote]', -8, ; // f

 

echo's

.

 

Now how do I check if text is posted above a

[quote=hey,January 1th] hey [/quote]

tag?

What does substr ($message, 0, 6); return if nothing is posted in front of a quote? :P

 

 

FINISHED AND SOLVED BABY!!!! I AM PRO

 

$checkquoteonly = substr($text, -13, 13);
 $checkquoteonly2 = substr($text, 0, 9);

 //Check if the first text contains "Quote"

 $check1 = stripos($checkquoteonly2, 'quote');
 /*

 echo   $checkquoteonly .'<br>';
 echo   $checkquoteonly2;
 */

	if ($check1 == true){
 if ($checkquoteonly == '--endquote-->'){
 message("You must enter a complete message.");
 }
 }

 

 

--endquote--> is what parses the quote message in my text into HTML, I just put a "<!--endquote-->" at the end of each quote so I can catch it it in the substr.

 

 

I only substr the --endquote-> part because if I did "<!--endquote-->" it wouldn't return any characters, it's bugged at ! question mark. (PHP BUG)

 

 

So then I checked if the first 9 characters of the string if it contained "quote" in them using stripos like ChristianF said :)

 

Then, ya u can see the rest of the code, Thanks ChristianF Topic solved!

 

Only problem now is if someone does:

 

Quote:

 

<--put quote message here -->

 

but I will just make a <!--quotestart--> when the text is being converted and switch it up just people don't say Quote: then link to a quote...

 

topic solved ty

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.