doa24uk Posted September 27, 2008 Share Posted September 27, 2008 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 Link to comment https://forums.phpfreaks.com/topic/126041-solved-check-for-certain-text-in-a-text-area/ Share on other sites More sharing options...
JasonLewis Posted September 28, 2008 Share Posted September 28, 2008 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. Link to comment https://forums.phpfreaks.com/topic/126041-solved-check-for-certain-text-in-a-text-area/#findComment-652108 Share on other sites More sharing options...
doa24uk Posted September 28, 2008 Author Share Posted September 28, 2008 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 } ?> Link to comment https://forums.phpfreaks.com/topic/126041-solved-check-for-certain-text-in-a-text-area/#findComment-652207 Share on other sites More sharing options...
corbin Posted September 28, 2008 Share Posted September 28, 2008 http://php.net/in_array You need a needle and a haystack. Example: if(in_array('something', $some_array)) So, in your case, you would want to do something like: if(in_array($fid, $fid_array)) Link to comment https://forums.phpfreaks.com/topic/126041-solved-check-for-certain-text-in-a-text-area/#findComment-652209 Share on other sites More sharing options...
doa24uk Posted September 28, 2008 Author Share Posted September 28, 2008 ahh I saw that I just wasn't sure whether $fid was defined already by virtue of being within the $fid_array ... is this the case or am I missing a step? sorry to sound like such a newbie! Link to comment https://forums.phpfreaks.com/topic/126041-solved-check-for-certain-text-in-a-text-area/#findComment-652214 Share on other sites More sharing options...
doa24uk Posted September 28, 2008 Author Share Posted September 28, 2008 nevermind. The fid is the actual variable of my forum ... sorry having a slow day today! Link to comment https://forums.phpfreaks.com/topic/126041-solved-check-for-certain-text-in-a-text-area/#findComment-652237 Share on other sites More sharing options...
doa24uk Posted September 28, 2008 Author Share Posted September 28, 2008 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 Link to comment https://forums.phpfreaks.com/topic/126041-solved-check-for-certain-text-in-a-text-area/#findComment-652254 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.