Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 8th, 2012  |  syntax: PHP  |  size: 0.61 KB  |  views: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. $string = '<a href="google.com/maps">Go to google maps</a> and some special characters ë è & ä etc.';
  4.  
  5. $string = htmlentities($string, ENT_QUOTES, 'UTF-8');
  6.  
  7. $doc = new DOMDocument('1.0', 'UTF-8');
  8. $doc->preserveWhiteSpace = false;
  9. $doc->formatOutput = true;
  10.  
  11. $root = $doc->createElement('top');
  12. $root = $doc->appendChild($root);
  13.  
  14. $title = $doc->createElement('title', $string);
  15. $title = $root->appendChild($title);
  16.  
  17. $id = $doc->createAttribute('id');
  18. $id->value = '1';
  19. $text = $title->appendChild($id);
  20.  
  21. $text = $title->appendChild($text);
  22.  
  23. $doc->save('data.xml');
  24.  
  25. echo 'data saved!';
  26. ?>
clone this paste RAW Paste Data