need help with removing [Rs]

Status
Not open for further replies.

bumilad20

Active Member
195
2009
0
0
jus A quick question .. does any1 know a way how .. that u can check on the topic title name for like

[Rs] , [[hf] etc and to get rid of it ?
 
15 comments
Someplace in the posting.php or newthread.php whatever the file is called you'll have to add a line of code like

PHP:
$title = preg_replace('[RS]', '', $title);

You can run it through a loop if you've loads.

PHP:
// This removes [RS] [HF] [HF RS] [FS] [MU] RS HF FS from titles
$removes = array('[RS]', '[HF]', '[HF RS]', '[FS]', '[MU]', 'RS', 'HF', 'FS');
while ($removes as $revove)
{
$title = preg_replace($remove, '', $title);
}
I have something like this built into LinkzBot for vB and IPB but I just haven't got round to learning PHPBB's framework to release it for PHPBB yet.

Sorry I can't be of any more help
 
MR Happy, you need to examine the speed of your code, your running preg repalce lots of times when you only need to run it once

PHP:
preg_replace("/(\[[RS|HF|FS|MU]\])?/","",$string); //UNTESTED

or you cauld possibly do something like

PHP:
preg_replace("/^(\[A-Z{2}\])/","",$string);

what this is doing is its only looking at the start of the line for the brace and if it finds an open brace it then looks for 2 letters that are upper-case, and that is followed by a closing brace. these are very strict characteristics of host prefixing rules.

if your worried about tags that have lower case then you could poss just add a i after the last slash in the compilation to make it case Insensitive.
 
MR Happy, you need to examine the speed of your code, your running preg repalce lots of times when you only need to run it once

PHP:
preg_replace("/\([[RS|HF|FS|MU]\])?/","",$string); //UNTESTED

I have it so they can enter their own prefixes they want removed in linkzbot which is saved to the DB settings as an array. It would be near impossible to convert individual user preferences to a usable regex that's why I have it the way I have it but yes your is way faster.

EDIT: Actually you have an error :O
 
not really do, you can implode the array and the preg_escape them like so

PHP:
$tags = array('RS','MS','FS','RS MU','MU');

$preg_compat = implode("|",$tags);

preg_replace("/\([[" . $preg_compat . "]\])?/","",$string); //UNTESTED

EDIT: Actually you have an error

what you want me to do, give you a cookie lol. i did say untested, example purposes and all that shizzle :P

yea i was escaping the capture brace, change that now :/
 
You would need to place litewarez code in Includes/functions_content.php

After
PHP:
		return preg_replace($censors['match'], $censors['replace'], $text);
	}


and change $string to $text in LiteWarez code



<<edit
Realised this is going to remove any tags in posts aswell, I will make a complete mod when litewarez code works
 
not really do, you can implode the array and the preg_escape them like so

PHP:
$tags = array('RS','MS','FS','RS MU','MU');

$preg_compat = implode("|",$tags);

preg_replace("/\([[" . $preg_compat . "]\])?/","",$string); //UNTESTED



what you want me to do, give you a cookie lol. i did say untested, example purposes and all that shizzle :P
I've tried something like this but it gets messy. You have people who have stuff like [RS/HF/FS/MU] or RS-HF or [RS|HF][MULIT] or RS+1 or RS*3 and lots of other stuff which mess with your regex and have to take into consideration. Have a look through some posts on WBB and the prefixes they use. I tried but you just get people posting the craziest patterns you'd never think of which affect it :(

In this case where he has control your is obviously better. I'm not arguing that fact.
 
yea you can do practically any string manipulation with regex, you just have to know all the modifiers and how there used to your advantage, such as lookahead and behind, and "or plus" stuff and that :/ works a treat if your skilled and willing to have good go at it :/
 
There is some error in the code litewarez gave i think.

I started making the complete mod to post, but some error in the function


Compilation failed: unmatched parentheses at offset 24



This isnt working in viewtopic either, is it the regex?

viewtopic.php
after
PHP:
// Replace naughty words in title
$topic_data['topic_title'] = censor_text($topic_data['topic_title']);

add
PHP:
$topic_data['topic_title'] = preg_replace("/^(\[A-Z{2}\])/","",$topic_data['topic_title']);
 
Status
Not open for further replies.
Back
Top