Jump to content

Array Help


Plug-in

Recommended Posts

I'm trying to make a XML api word blacklist and I'm able to get all the information fine but I'm confusing myself with the array, could you please help, this is my code:

<pre>
<?php
$data = file_get_contents("http://api.jspace.netai.net/blacklist.xml");
$data = simplexml_load_string($data);



//foreach ($data->words->word as $word) {
  //echo (string)$word;
//}

function filter_words($text, $data) {
foreach($data->words->word as $w) {
  $string = str_replace((string)$w, '[!]', strtolower($text));
  return strtoupper($string);
}
}

echo filter_words("Sentence containing unfiltered word - shit.", $data);

?>
</pre>

 

The problem is it returns unfiltered

Link to comment
https://forums.phpfreaks.com/topic/246015-array-help/
Share on other sites

I'm sorry if I look like I want to be spoon fed but I cannot understand why this will not work, the updated code is below and still does not return [!], sorry for the cuss words:

<pre>
<?php
$data = file_get_contents("http://api.jspace.netai.net/blacklist.xml");
$data = simplexml_load_string($data);

function filter_words($text, $data) {
  foreach($data->words->word as $w) {
  $string = str_replace(strtolower((string)$w), '[!]', strtolower($text));
  }
return strtoupper($string);
}

echo filter_words("fuck", $data);

?>
</pre>

Link to comment
https://forums.phpfreaks.com/topic/246015-array-help/#findComment-1263449
Share on other sites

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.