XML Feed Problem with £ and ' any ideas.... anyone???

Please support our XML, XSLT and XPATH advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2009
Posts: 23
Reputation: Facte is an unknown quantity at this point 
Solved Threads: 0
Facte's Avatar
Facte Facte is offline Offline
Newbie Poster

XML Feed Problem with £ and ' any ideas.... anyone???

 
0
  #1
Oct 21st, 2009
Hi there everyone. Does anyone have any idea how to stop my xml feed displaying # instead of £ and companys instead of company's.

I've tried everything I can think of. In UTF-8 it won't show hardly anything in ASCII it works but still spits out thhe errors above.


XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.  
  4. <head>
  5. <meta content="text/html; charset=ASCII" http-equiv="Content-Type" />
  6. <title>RAD Feed</title>
  7. </head>
  8.  
  9. <body>
  10.  
  11. <?php
  12. include "development/StripAttributes.php";
  13. $username = "******"; //Database Username
  14. $password = "*******"; //Database Password
  15. $hostname = "*******"; //Database Host
  16. $dbname = "******"; //Database (or Catalog in MySQL parlance) name
  17. $dbh = mysql_connect($hostname, $username, $password) or die("Could not connect to database server");
  18. $selected = mysql_select_db($dbname, $dbh) or die("Database not found or problem connecting");
  19. $result = mysql_query("SELECT expiry, position, postdate, jobref, salary, jobid, subcounty, country, description FROM jobs");
  20.  
  21. function stripchars($str)
  22. {
  23. $row = htmlentities("$str");
  24. $row = ereg_replace(128, "&euro;", $row); // Euro symbol
  25. $row = ereg_replace(133, "…", $row); // ellipses
  26. $row = ereg_replace("&nbsp;", " ", $row); // space
  27. $row = ereg_replace("&", "&amp;", $row); // and "&", "&amp;",
  28. $row = ereg_replace(8226, "″", $row); // double prime
  29. $row = ereg_replace(8216, "'", $row); // left single quote
  30. $row = ereg_replace(145, "'", $row); // left single quote
  31. $row = ereg_replace(8217, "'", $row); // right single quote
  32. $row = ereg_replace(146, "'", $row); // right single quote
  33. $row = ereg_replace(8220, """, $row); // left double quote
  34. $row = ereg_replace(147, """, $row); // left double quote
  35. $row = ereg_replace(8221, """, $row); // right double quote
  36. $row = ereg_replace(148, """, $row); // right double quote
  37. $row = ereg_replace(8226, "•", $row); // bullet
  38. $row = ereg_replace(149, "•", $row); // bullet
  39. $row = ereg_replace(8211, "–", $row); // en dash
  40. $row = ereg_replace(150, "–", $row); // en dash
  41. $row = ereg_replace(8212, "—", $row); // em dash
  42. $row = ereg_replace(151, "—", $row); // em dash
  43. $row = ereg_replace(8482, "™", $row); // trademark
  44. $row = ereg_replace(153, "™", $row); // trademark
  45. $row = ereg_replace(169, "&copy;", $row); // copyright mark
  46. $row = ereg_replace(174, "&reg;", $row); // registration mark
  47. $row = ereg_replace("","’",$row);//fix SQL
  48. $final = htmlentities("$row");
  49.  
  50. return $final;
  51.  
  52. }
  53.  
  54. // if the file exists already, delete it first to flush data
  55. $xmlfeedfile = "rad.xml";
  56. $filehandle = fopen($xmlfeedfile, 'w');
  57. $itemLink = $fullurl.'/info_jobid_'. $b[jobid].'.html';
  58.  
  59. $xmlString = '<'.'?'.'xml version="1.0" encoding="ASCII" '.'?' .'>
  60. <source>
  61. <publisher> EditorialJobs.co.uk</publisher>
  62. <publisherurl> http://www.EditorialJobs.co.uk</publisherurl> ';
  63. fwrite($filehandle, $xmlString);
  64. while ($row = mysql_fetch_assoc($result)) {
  65. if(strtotime($row['expiry']) < time()) {
  66. continue;
  67. }
  68. $pos = stripslashes(strip_tags($row['position']));
  69. $date = stripslashes(strip_tags($row['postdate']));
  70. $ref = stripslashes(strip_tags($row['jobref']));
  71. $desc = stripslashes(strip_tags($row['description']));
  72. $cnt = stripslashes(strip_tags($row['country']));
  73. $sal = stripslashes(strip_tags($row['salary']));
  74. $loc = stripslashes(strip_tags($row['subcounty']));
  75. $jid = stripslashes($row['jobid']);
  76. $desc = preg_replace('/&nbsp;/', ' ', $desc);
  77. $desc = preg_replace('/&/', '/&amp;/', $desc);
  78. $desc = preg_replace('/&apos;/', "'", $desc);
  79. $desc = preg_replace('/#/', '£', $desc);
  80. $pos = preg_replace('/&nbsp;/', ' ', $pos);
  81. $pos = preg_replace('/&/', '/&amp;/', $pos);
  82. $sal = preg_replace('/&nbsp;/', ' ', $sal);
  83. $sal = preg_replace('/&/', '/&amp;/', $sal);
  84. $sal = preg_replace('/£/', '&pound;', $sal);
  85.  
  86. $xmlString = "<job>\n\t<title><![CDATA[{$pos}]]></title>\n\t<date><![CDATA[{$date}]]></date>\n\t<referencenumber><![CDATA[{$ref}]]></referencenumber>\n\t<salary>{$sal}</salary>\n\t<url><![CDATA[http://www.editorialjobs.co.uk/info_jobid_{$jid}.html]]></url>\n\t<city><![CDATA[{$loc}]]></city>\n\t<country><![CDATA[{$cnt}]]></country>\n\t<description><![CDATA[{$desc}]]></description>\n</job>";
  87.  
  88. fwrite($filehandle, $xmlString);
  89. }
  90. mysql_close($dbh);
  91. fwrite($filehandle, "</source>");
  92. fclose($filehandle);
  93. ?>
  94.  
  95. </body>
  96.  
  97. </html>
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for XML, XSLT and XPATH
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC