Jump to content

fwrite() to an html file, different encoding?


noctrum

Recommended Posts

Greetings,

 

I'm setting up a store with Yahoo (ugh), and I wrote a simple php script that generates an individual page for each of my items with the appropriate store tags.  The problem is that I have a bunch of double quotes throughout the HTML, and one of the last ones (and only one of the double quotes) appears to be ascii encoded rather than utf-8, like the rest of the file, which is keeping the store tags from working.  Simply editing the file and saving it without making any changes will fix the problem, but there are over 14,000 of these files, so doing that for each one isn't really an option.  Relevant code is below, sample non-working page is: http://www.strangelandrecords.com/shop/58.html

 

The quote is the one directly after $row['code'] here:

 

<form method="post" action="<!--#ystore_order id="' . $row['code'] . '"-->">

 

I have tried the way it is below and by encapsulating the string in double quotes and escaping all of the double quotes being written with the same result.  I'm hoping someone can shed some light on why one of the double quotes in the file would be behaving differently when all of the ones I'm writing are identical?

 

$sql = "SELECT * FROM `table`";
$result = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_array($result)){
$filename = $row['code'];
$filename .= ".html";

$toWrite = fopen($filename,'w');

$buf = '

...

<span class="sectionName">Shop &#187; <!--#ystore_catalog id="' . $row['code'] . '" field="abstract" --> &#187; <!--#ystore_catalog id="' . $row['code'] . '" field="name" --></span>
				</div>
				<div id="rightContent"><h2>Add this item to your cart?</h2>
					<p><b>Artist:</b> <!--#ystore_catalog id="' . $row['code'] . '" field="abstract" -->
					<br/><b>Title:</b> <!--#ystore_catalog id="' . $row['code'] . '" field="name" -->
					<br/><b>Format:</b> <!--#ystore_catalog id="' . $row['code'] . '" field="format" -->
					<br/><b>Price:</b> $<!--#ystore_catalog id="' . $row['code'] . '" field="price" --></p>
					<form method="post" action="<!--#ystore_order id="' . $row['code'] . '"-->">
						<input type="submit" value="Order">
					</form>
				</div>
...

';
fwrite($toWrite,utf8_encode($buf));
fflush($toWrite);
ftruncate($toWrite,ftell($toWrite));

fclose($toWrite);
}

?>

 

help?  ???

Archived

This topic is now archived and is closed to further replies.

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