My head is going to explode if I can't fix this. PLEASE HELP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Facte
Forum Newbie
Posts: 6
Joined: Mon Jul 20, 2009 8:44 am

My head is going to explode if I can't fix this. PLEASE HELP

Post by Facte »

Hi there everyone. I have a problem with some PHP.

I have to make a xml feed that works in IE in UTF-8 format and I'm having major problems with £ signs and '. the poud signs are in the mySQL database in their £ format and cannot be changed.

I've tried adding preg_replaces, ereg_replaces and str_replaces, no joy.

Here is the basic code which pulls all the right info, just with ? instead of £ and apostrophes.

Please help.

Code: Select all

<?php
$username = ""; //Database Username
$password = ""; //Database Password
$hostname = ""; //Database Host
$dbname = ""; //Database (or Catalog in MySQL parlance) name
$dbh = mysql_connect($hostname, $username, $password) or die("Could not connect to database server");
$selected = mysql_select_db($dbname, $dbh) or die("Database not found or problem connecting");
$result = mysql_query("SELECT employerid, expiry, postdate, position, hour, contract, salary, subcounty, description, jobref, jobid FROM jobs");
 
// if the file exists already, delete it first to flush data
$xmlfeedfile = "trovit.xml";
$filehandle = fopen($xmlfeedfile, 'w');
$itemLink  = $fullurl.'/info_jobid_'. $b[jobid].'.html';
 
$xmlString = '<'.'?'.'xml version="1.0" encoding="utf-8" '.'?' .'>
<trovit>';
fwrite($filehandle, $xmlString);
while ($row = mysql_fetch_assoc($result)) {    
if(strtotime($row['expiry']) < time()) {        
continue;    
}
 
$pos = ($row['position']);
$date = ($row['postdate']);
$ref = ($row['jobref']);
$desc = ($row['description']);
$jid = ($row['jobid']);
$sal = ($row['salary']);
$loc = ($row['subcounty']);
 
$xmlString = "<ad>\n\t<id><![CDATA[{$ref}]]></id>\n\t<title><![CDATA[{$pos}]]></title>\n\t
<url><![CDATA[http://www.xxxxxxxxxxxxx.co.uk/info_jobid_{$jid}.html]]></url>\n\t<content><![CDATA[{$desc}]]></content>\n\t<city><![CDATA[{$loc}]]></city>\n\t<salary><![CDATA[{$sal}]]></salary>\n\t<date><![CDATA[{$date}]]></date>\n</ad>";
fwrite($filehandle, $xmlString);
}
mysql_close($dbh);
fwrite($filehandle, "</trovit>");
fclose($filehandle);
?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: My head is going to explode if I can't fix this. PLEASE HELP

Post by requinix »

What's the encoding of the database table?
Facte
Forum Newbie
Posts: 6
Joined: Mon Jul 20, 2009 8:44 am

Re: My head is going to explode if I can't fix this. PLEASE HELP

Post by Facte »

The coding of the DB is UTF-8
Post Reply