Results 1 to 3 of 3

Thread: [RESOLVED] str_replace(), ob_start() and UTF-8

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    121

    [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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width