SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Replace special chars not tags, php trigered by html

    Good day to you all,
    I working on a code which take a txt file and display it through php, but this thing is triggered by ajax.

    in the txt files there is html tags and html special chars.


    What I'm trying to do is encode only the special chars.
    ex :

    Php read those character not a problem, it when I pass it by ajax that i get some weird chars like squares with a question mark.

    Does anybody have an idea on how I can fix this ?


    Here is the code that get triggered when i click on a ajax link :
    PHP Code:

    <?php
    $textsectb 
    file_get_contents('dep_en_tb.txt');
    $textsechttb htmlentities($textsectb);
    echo 
    $textsechttb;
    ?>
    I only need to replace the special char not the html tags.

    Thanks!

  2. #2
    SitePoint Addict Mal Curtis's Avatar
    Join Date
    Jul 2009
    Location
    New Zealand
    Posts
    327
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Sounds like it's returning a string encoded in a character set different to what your main page (the calling page) is using. Find out what character set your main page is using, and ensure it's sent through as the third parameter to the htmlentities function (see manual page).

    http://us3.php.net/manual/en/function.htmlentities.php

    Oh, and the fourth parameter for double_encoding will ensure html tags are not double encoded.


Bookmarks

Posting Permissions

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