string replacer using XML array

Posted under » PHP on 31 March 2013

Normally this is done thru a mysql database but I find it tedious to add or edit it. So using an XML is a good idea.

Here is my XML file.


Here is my PHP file.

$lib = simplexml_load_file("terms.xml");
// convert the xml into arrays
foreach($lib as $terms){
  $wr0ng[] = $terms->wrong;
  $r1ght[] = $terms->right;
// replace using the derived arrays
$content = str_replace($wr0ng, $r1ght, $content);

This is actually a combination of these following ideas.
array string replacer
XML to Arrays

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS