Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4271028
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:23:10+00:00 2026-05-21T07:23:10+00:00

Part of our web app has a little Ajax method that will load a

  • 0

Part of our web app has a little Ajax method that will load a page in an iFrame or allow you to download it.

We store a bunch of search results from search engines and we have script opens the file containing our info and the search html. We strip out the stuff we don’t need from the top (our info) and then we serve that up either by echo’ing the $html variable or putting it in a temporary file and dishing it off to download.

The problem: I load the page in the iFrame and it’s loaded in UTF-8 because everything else is. If I download the file manually it is fine and FF tells me the endoding is x-gbk.

I’ve tried using mb_convert_encoding to no avail. We are using PHP4 on this server.

Thoughts?

EDIT: Code that drives this

f(!isset($_GET['file']) || $_GET['file'] == '')
{
    header("location:index.php");
}
$download = false;

if(!isset($_GET['view']) || $_GET['view'] != 'true')
{
    $download = true;
}

$file = LOG_PATH . $_GET['file'];

$fileName = end(explode("/", $file));

$fh = fopen($file, "rb");

if(!$fh)
{
    echo "There was an error in processing this file. Please retry.";
    return;
}

// Open HTML file, rip out garbage at top, inject "http://google.com" before all "images/"
$html = fread($fh, filesize($file));
fclose($fh);

// Need to trim off our headers
$htmlArr = explode("<!", $html, 2);
$htmlArr[1] = "<!" . $htmlArr[1];   

if(strstr($file, "google"))
{
    $html = str_replace('src="/images/', 'src="http://google.com/images/', $htmlArr[1]);
    $html = str_replace('href="/', 'href="http://google.com/', $html);
}
else if(strstr($file, "/msn/"))
{
    $html = str_replace('src="/images/', 'src="http://bing.com/images/', $htmlArr[1]);
    $html = str_replace('href="/', 'href="http://www.bing.com/', $html);    
}
else
{
    $html = $htmlArr[1];
}

if(strstr($file, "baidu"))
{
    $html = mb_convert_encoding($html, 'utf-8'); // Does not work
}

if($download)
{   
    // Write to temporary file
    $fh = fopen("/tmp/" . $fileName, 'w+');
    fwrite($fh, $html);
    fclose($fh);

    $fh = fopen("/tmp/" . $fileName, "rb");
    header('Content-type: application/force-download;');
    header("Content-Type: text/html;");
    header('Content-Disposition: attachment; filename="' . $fileName . '"');
    fpassthru($fh);
    fclose($fh);
    unlink("/tmp/" . $fileName);
}
else // AJAX Call
{
    echo $html;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:23:11+00:00Added an answer on May 21, 2026 at 7:23 am

    You may want to try iconv() instead of mb_convert_encoding()–it has support for a much broader set of encodings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a web app that will be working with other companies web
As part of our web application's build process, I have set up our XSLT
Part of our java application needs to run javascript that is written by non-developers.
I'm working on a web app that reads data from a set of text
We've having trouble deploying a web service that works in our development environment, but
I'm looking to create a mobile version of our website/web app. What's a good
I have a very dynamic web app that is dynamically created controls at run-time.
I'm currently developing a moderately large sized web app with ASP.NET 2.0 that uses
We are using Rails 3.0.X and running our web app on Heroku. We are
I'm building a web app where the vast majority of our target audience likely

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.