4 Replies - 997 Views - Last Post: 02 May 2011 - 02:54 PM Rate Topic: -----

#1 IrisBlaze   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-August 10

Replace all accuracies of bad words but not in safe tag

Posted 02 May 2011 - 02:08 PM

Hello,

I have this problem,
let's say that i have the following sentence

bad word [safe]notbad[/safe] word, verybad word.

I want the output to be like this:
*** word notbad word, ******* word.

any help?

Thanx
Is This A Good Question/Topic? 0
  • +

Replies To: Replace all accuracies of bad words but not in safe tag

#2 KingCuddles   User is offline

  • D.I.C Regular

Reputation: 176
  • View blog
  • Posts: 496
  • Joined: 20-December 08

Re: Replace all accuracies of bad words but not in safe tag

Posted 02 May 2011 - 02:33 PM

This should be a fairly simple thing to achieve, I built something which pretty much does that but it converts BBCode into HTML. I did it using preg_replace.

Have you tried to do this yourself?

This post has been edited by KingCuddles: 02 May 2011 - 02:36 PM

Was This Post Helpful? 0
  • +
  • -

#3 IrisBlaze   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-August 10

Re: Replace all accuracies of bad words but not in safe tag

Posted 02 May 2011 - 02:40 PM

View PostKingCuddles, on 02 May 2011 - 02:33 PM, said:

This should be a fairly simple thing to achieve, I built something which pretty much does that but it converts BBCode into HTML. I did it using preg_replace.

Have you tried to do this yourself?


you have no idea what i am talking about then, i did like thousands of BBCode before this is not the same, i am not trying to replace what's in the tag, i am trying to replace what's not, and yes i've been trying with preg_replace, and preg_match since 3 hours, i am running out of time, so please don't post useless answers
Was This Post Helpful? 0
  • +
  • -

#4 KingCuddles   User is offline

  • D.I.C Regular

Reputation: 176
  • View blog
  • Posts: 496
  • Joined: 20-December 08

Re: Replace all accuracies of bad words but not in safe tag

Posted 02 May 2011 - 02:42 PM

No need to be an ass about it, its really simple to do using preg_match - Ive just built a quick sample which works fine.

If you post your preg_match code I will be happy to help you out.
Was This Post Helpful? 1
  • +
  • -

#5 IrisBlaze   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-August 10

Re: Replace all accuracies of bad words but not in safe tag

Posted 02 May 2011 - 02:54 PM

View PostKingCuddles, on 02 May 2011 - 02:42 PM, said:

No need to be an ass about it, its really simple to do using preg_match - Ive just built a quick sample which works fine.

If you post your preg_match code I will be happy to help you out.


as i said this will only help in replacing the word between tags:
$pattern = "/\[safe\](.*?)\[\/safe\]/is";
    $word = preg_replace($pattern, "?", $word);

You see if the input was "don't be an ass or i will assassinate you", and then my first function which tags the safe words will make the input like this "don't be an ass or i will [safe]assassinate[/safe] you".

now with that code the output will be : "don't be an ass or i will ? you".
but what i am trying to do is replacing the word ass, str_ireplace will output this:
"don't be an *** or i will ******inate you".
what i want is a regex or any other method to replace ass, but not assassinate
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1