Jump to content

php special characters


lhbdan

Recommended Posts

So i want to save all of the output in my file to a .prc file. I am using ob_start(); and ob_get_contents(); to do this, so all of the echo's in the script are then stored into this file. The file needs a header and a footer, they are attached below, and they have special characters in them. When saved into the prc format, these special characters need to be as are written into the script, but they are changed. Here is an example of what I have going:

<?php

ob_start();

$header = "SMHMü«∂Mü«∂BOOKMOBI‡

XX*X:XJXZXjXzXäX öX

™X∫X X

ŒöŒúŒ¿ŒÏƒB

MOBIˉ¢Bˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇp PˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇEXTHx,:Ä æÙÌÏÔ@î@ì@ô@ò@ú@ùÃÕŒœ)SMH<html><head><guide></guide></head><body>";

 

echo $header;

$body = "Hello";

$footer ="<mbp:pagebreak/></body></html>FLISAˇˇˇˇˇˇˇˇFCISƒB Èé";

echo $footer;

$out = ob_get_contents();

ob_end_clean();

$file = fopen("smh.prc","w");

file_put_contents("smh.prc",$out);

fclose($file);

?>

 

This script works, and creates the .prc file, though when i look at the prc code, the header is this rather than what was in the script:

 

SMHMü«∂Mü«∂BOOKMOBI‡

XX*X:XJXZXjXzXäX öX

™X∫X XŒöŒúŒ¿ŒÏƒBMOBIˉ¢Bˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇp PˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇEXTHx,:Ä æÙÌÏÔ@î@ì@ô@ò@ú@ùÃÕŒœ

 

A similar thing has happened in the footer. How can i make an exception for these, and save the characters as the special characters, rather than these replacements? I am not sure what encoding these characters are from.

Link to comment
Share on other sites

Try this:

<?php
ob_start();
$header = "SMHMü«∂Mü«∂BOOKMOBI‡
XX*X:XJXZXjXzXäX   öX
™X∫X X
ŒöŒúŒ¿ŒÏƒB
MOBIˉ¢Bˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇp   PˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇEXTHx,:Ä æÙÌÏÔ@î@ì@ô@ò@ú@ùÃÕŒœ)SMH<html><head><guide></guide></head><body>";

echo $header;
$body = "Hello";
$footer ="<mbp:pagebreak/></body></html>FLISAˇˇˇˇˇˇˇˇFCISƒB Èé";
echo $footer;
$out = ob_get_clean();
file_put_contents("smh.prc", utf8_encode($out));
?>

Not really sure why you use output buffering, since everything you have there could easily be put into one variable instead.

I took out some code because

a) you don't need to fopen() and fclose() a file if you're going to use file_put_contents

b) ob_get_contents and ob_end_clean can be combined into one call (ob_get_clean)

 

Also, please put your code in


tags next time :)

Link to comment
Share on other sites

It still hasn't worked, this time my output (for the header) was;

SMHMü«&#8706;Mü«&#8706;BOOKMOBI‡
XX*X:XJXZXjXzX√ɬ§X   √ɬ∂X
™X&#8747;X X
ŒöŒúŒ¿ŒÏƒB
MOBI√ɬã√¢¬Ä¬∞√Ǭ¢B&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;p   P&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;&#711;EXTHx,:√É¬Ñ √ɬ¶√ɬô√ɬå√ɬè√ɬî@√ɬÆ@√ɬ¨@√ɬ¥@√ɬ≤@√ɬ∫@√ɬπ√ɬÉ√ɬï√Ö¬í√Ö¬ì)SMH<html><head><guide></guide></head><body>

Link to comment
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.