Jump to content

: : How to format loads of words


anevins

Recommended Posts

Hi there,

 

I have a HUGE list of inappropriate words in plain text, but the thing is, I want to use these bad words in an array.

 

But I can't just copy and paste the bad words into the array, as each bad word needs to have two apostraphes aside one another.

 

E.g the array should be:

$bad_words = array('badword1','badword2','badword3');

 

but my text document just has:

badword1

badword2

badword3

 

How do I format the bad words to have apostraphes aside each other?

I don't want to manually go through each word.

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/232517-how-to-format-loads-of-words/
Share on other sites

If you have them in a text file, with each word on a separate line, you could just do this to create your array:

 

<?php

$file = "/path/to/file/bad_words.txt";
$handle = fopen($file, "r");
$contents = fread($handle, filesize($file));

$bad_words = explode("\n", $contents);

?>

: : NEW Problem

 

I want to replace bad words which someone has inputted into my HTML textarea, with something like [CENSORED].

Here's what I've got so far:

note: $review is the posted textarea name.

$words_text = 'badwords.txt';
$bad_words = file($words_text);

$good_words = str_ireplace($bad_words,'[CENSORED]',$review);

echo $good_words;

 

The thing is, if I type bad words in the textarea, I still get bad words when I echo $good_words.

 

I don't know why I'm getting this, any ideas?

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.