Jump to content

Recommended Posts

Hi,

 

Im extracting my product data from the database to store in an XML file for the Google Product Listings.

 

The problem I'm having is that there are a number of incompatible characters in some of the data that is causing the XML file, once generated to be invalid.

 

There are a huge number of products in the database (60,000+) so it would take an age to go through each product and remove any rogue characters, so I am using preg_replace.

 

I've managed to find the rogue characters that occur in the data and used the preg_replace function to strip out these characters. Below is a code sample:

 

$narrLong = strip_tags(nl2br($productArr['narrLong']));
$narrLong = htmlentities(html_entity_decode(preg_replace("/\t/"," ",$narrLong)),ENT_QUOTES,UTF-;
$narrLong = preg_replace("/£/","�",$narrLong);
$narrLong = preg_replace("/Â/","",$narrLong);
$narrLong = preg_replace("/ /"," ",$narrLong);
$narrLong = html_entity_decode($narrLong);
$narrLong = preg_replace("/ & /"," & ",$narrLong);
$narrLong = preg_replace("/(\w)&(\w)/","$1&$2",$narrLong);
$narrLong = preg_replace("/\"/",""",$narrLong);
$narrLong = preg_replace("/'|`/","'",$narrLong);
$narrLong = preg_replace("/</","<",$narrLong);
$narrLong = preg_replace("/>/",">",$narrLong);
$narrLong = preg_replace("/“/","'",$narrLong);
$narrLong = preg_replace("/”/","'",$narrLong);
$narrLong = preg_replace("/’/","'",$narrLong);
$narrLong = preg_replace("/½/"," 1/2",$narrLong);
$narrLong = preg_replace("/®/","",$narrLong);
$narrLong = preg_replace("/£/","",$narrLong);
$narrLong = preg_replace("/µ/", "u",$narrLong);
$narrLong = preg_replace("/é/", "e",$narrLong);
$narrLong = preg_replace("/è/", "e",$narrLong);
$narrLong = preg_replace("/’/", "'",$narrLong);
$narrLong = preg_replace("/…/", "...",$narrLong);
$narrLong = preg_replace("/°/", "",$narrLong);
$narrLong = preg_replace("/™/", "",$narrLong);
$narrLong = preg_replace("/—/", "-",$narrLong);
$narrLong = preg_replace("/Ã/", "",$narrLong);
$narrLong = preg_replace("/ƒ/", "",$narrLong);
$narrLong = preg_replace("/¨/", "",$narrLong);
$narrLong = preg_replace("/©/","",$narrLong);
$narrLong = preg_replace("/¤/", "",$narrLong);
$narrLong = str_replace("·", "",$narrLong);
$narrLong = preg_replace("/‰/", "",$narrLong);
$narrLong = preg_replace("/¹/", "",$narrLong);

 

I then plug my xml open and close tags onto either end etc...

 

However, once the xml file is generated and saved, none of the characters that I've asked to replace have not been replaced and remain in the XML file.

 

Is there something I'm doing wrong? Are some of the characters not being recognised in my script in the first place?

 

Thanks for your help.

Link to comment
https://forums.phpfreaks.com/topic/234254-xml-file/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.