|
-
Sep 24th, 2008, 09:02 AM
#1
Thread Starter
Lively Member
[RESOLVED] str_replace(), ob_start() and UTF-8
Hello all.
Trying to build an application which replaces strings within an html page with elements from an array.
I can't figure out what I'm doing wrong here. I've got an external file named ru.txt. It has Russian text in it, hopefully it will display here:
Code:
<?
$txt[0]="что компания является";
?>
My index page, which includes the text file, looks like this:
Code:
<?php
/* MAKE CERTAIN WE USE UTF-8 ENCODING */
header("Content-type: text/html; charset=utf-8");
/* INCLUDE THE APPROPRIATE LANGUAGE FILE */
include_once('_includes/ru.txt');
/* THE CALLBACK FUNCTION */
function callback($buffer) {
/* LOOP THROUGH THE ARRAY, MAKING THE APPROPRIATE REPLACEMENTS */
for($i=0; $i<count($GLOBALS['txt']); $i++) {
$buffer=str_replace('{txt_'.$i.'}',$GLOBALS['txt'][i],$buffer);
}
/* RETURN IT */
return $buffer;
}
/* BEGIN THE OUTPUT OBJECT */
ob_start("callback");
?><html>
<head>
<title>test</title>
<meta http-equiv="Content-type" value="text/html; charset=utf-8">
</head>
<body>{txt_0}</body>
</html><?
/* END THE OUTPUT OBJECT */
ob_end_flush();
?>
I am getting an empty page (nothing within the body tags.)
Both files have been saved with UTF-8. If I hard-code the str_replace with something like "blah" it works fine. If I remove the whole callback procedure and echo the $txt[0] from the external file, it works fine.
Any clues as to what I'm doing wrong?
Muchos thanks.
Last edited by solitario; Sep 24th, 2008 at 09:05 AM.
Reason: resolved
-
Sep 24th, 2008, 09:05 AM
#2
Thread Starter
Lively Member
Re: str_replace(), ob_start() and UTF-8
Duh, I fixed it. Doing too much JavaScript lately. I forgot the $ in the second parameter of the str_replace.
-
Sep 24th, 2008, 10:06 AM
#3
Re: [RESOLVED] str_replace(), ob_start() and UTF-8
You should set the error reporting level so you can see errors like that. It will make the task of debugging 1000 times easier. In the PAP.ini file change the line error_reporting to:
Code:
error_reporting = E_ALL
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|