Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Encode spanish characters in html and display

    I have a script that is currently serving as a course content management system which simply displays all media in a directory in a list of links that look like this index.php?action=showfile&filename=filename.mp3&type=mp3

    where type determines wich directory to look for filename.mp3 (audio) and filename is of course the filename.

    for this filename.mp3 file, it would also be accompanied by a filename.mp3.dia which is only a text file with spanish text.

    I need to read this text file and encode all special characters into html which I have accomplished by using this little bit of code:

    PHP Code:
    function encode_dialogue($file){

      
    $lines file($file);

      foreach (
    $lines as $key => $value){

        
    $encoded_value encode_accents($value);
        
    $lines[$key] = $encoded_value;

        
    header("Content-type: text/html");
        
    $dia .= $lines[$key];

      }

      return 
    $dia;

    }

    function 
    encode_accents($text){

      foreach(
    get_html_translation_table(HTML_ENTITIES) as $a=>$b){

        
    $text str_replace($a,$b,$text);

      }

      return 
    $text;


    I call the function encode_dialogue() like this:

    PHP Code:
    $myVariable encode_dialogue($url_to_filename.mp3.dia); 
    When I call the variable $myVariable in my php generated html page, the text appears except the html codes like:

    Code:
    ¡
    just display like this and aren't parsing???

    any Ideas???
    Last edited by titanic_fanatic; 12-20-2006 at 05:59 PM. Reason: typo in last sentence

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    You mention a PHP generated page ...

    Show us more about that part, how you generate the page.
    Are you defining this in your generated page?
    <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">

  • #3
    New Coder
    Join Date
    Jul 2005
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    You mention a PHP generated page ...

    Show us more about that part, how you generate the page.
    Are you defining this in your generated page?
    <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
    I just figured out what the problem was... it was for some reason changing all of the & to &amp; and screwing up everything so I changed this function:

    PHP Code:
    function encode_accents($text){

      foreach(
    get_html_translation_table(HTML_ENTITIES) as $a=>$b){

        
    $text str_replace($a,$b,$text);

      }

      return 
    $text;


    to this function:

    PHP Code:
    function encode_accents($text){

      foreach(
    get_html_translation_table(HTML_ENTITIES) as $a=>$b){

        if (
    $b != "&amp;"){

          
    $text str_replace($a,$b,$text);

        }

      }

      return 
    $text;


    and now it works just fine...

    thanks hint on encoding, that kind of what made me dig a little more...

    Titanic_Fanatic


  •  

    Posting Permissions

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