Jump to content

[SOLVED] check for certain text in a text area


doa24uk

Recommended Posts

Hi guys,

 

I operate a forum & need some way to force users to input certain text when they submit a new thread.

 

ie. Each new thread in certain forums must contain a link within [HIDE] tags [/HIDE]

 

Therefore I can imagine the loop being something like this (would it be better to use case rather than if ... else?)

 

If forum id=2,4,23,25 ... list all affected board id's here

//CODE to check whether or not the text '[HIDE]' and '[/HIDE]' (without 's) are present in the message

}

True  - [HIDE] and [/HIDE] ARE present --> Post message

}

Else (False [HIDE] and [/HIDE] AREN'T present) --> Return to new thread page with an error message of some sort.

 

 

Thanks for the help guys

 

What you could do is put all the affected forum id's in an array of some sort, just an indexed array. Then use in_array() to check if the current forum's id is one that needs the tags.

Then you can use regular expressions to check for the [HIDE][/HIDE] tags. Where you would put this I cannot say because each different forum packages differs with the way they handle posting threads and what not.

Please bear with me, first time I've used arrays.

 

So would it look like this??

 

<?php

$fid_array[0] = "13";
$fid_array[1] = "14";
$fid_array[2] = "15";
$fid_array[3] = "20";
$fid_array[4] = "26";
$fid_array[6] = "27";
$fid_array[7] = "28";
$fid_array[8] = "29";
$fid_array[9] = "30";
$fid_array[10] = "31";
$fid_array[11] = "32";
$fid_array[12] = "33";
$fid_array[13] = "34";
$fid_array[14] = "35";
$fid_array[15] = "36";
$fid_array[16] = "37";
$fid_array[17] = "38";
$fid_array[18] = "39";
$fid_array[19] = "40";
$fid_array[20] = "41";
$fid_array[21] = "42";
$fid_array[22] = "43";
$fid_array[23] = "44";
$fid_array[24] = "45";
$fid_array[25] = "46";
$fid_array[26] = "47";

if (in_array($fid_array)) {
// DO REGEXP
}
?>

Ok,

 

I now have the following two php if loops. Just need to combine em

 

Original Array

 

<?php
$fid_array[0] = "13";
$fid_array[1] = "14";
$fid_array[2] = "15";
$fid_array[3] = "20";
$fid_array[4] = "26";
$fid_array[6] = "27";
$fid_array[7] = "28";
$fid_array[8] = "29";
$fid_array[9] = "30";
$fid_array[10] = "31";
$fid_array[11] = "32";
fid_array[12] = "33";
$fid_array[13] = "34";
$fid_array[14] = "35";
$fid_array[15] = "36";
$fid_array[16] = "37";
$fid_array[17] = "38";
$fid_array[18] = "39";
$fid_array[19] = "40";
$fid_array[20] = "41";
$fid_array[21] = "42";
$fid_array[22] = "43";
$fid_array[23] = "44";
$fid_array[24] = "45";
$fid_array[25] = "46";
$fid_array[26] = "47";
  
if(in_array($forumid, $fid_array)) {
// TEST REGEX FOR HIDE TAGS
}
else{
// DO NOTHING
}
?>

 

And combined code

 

<?php

$fid_array[0] = "13";
// ALL OTHER $fid_arrays

if(in_array($forumid, $fid_array)) {
$tests = array(
'... [hide] and [/hide] ...',
'as well as [HIDE] and [/HIDE] xyz',
'and [hide] and [hide] abc',
'or [hide] and [/HIDE] ...',);

foreach($tests as $t) {
if(preg_match('#\[(hide|HIDE)\].*?\[/\1\]#', $t)) {
// [HIDE] AND [/HIDE] (OR ANY CAPS PERMUTATION OF THESE) ARE PRESENT
// DO NOTHING AND EXECUTE SCRIPT AS NORMAL
} else {
// TAGS AREN'T PRESENT. EXECUTE ERROR CODE.
}
}
}
else{
// DO NOTHING
}
?>

Is this correct??

 

Thanks again

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.