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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2009
    Location
    somewhere over the rainbow
    Posts
    105
    Thanks
    2
    Thanked 14 Times in 14 Posts

    fread strip html tags

    i'm reading a text file and it strips html tags like fgetss.
    why does it happen?

    I tried file_get_contents and fread but not reading the tags.

    e.g
    data.txt
    Code:
    today is a <new> green day
    file.php
    PHP Code:
    $file='data.txt';
    $fh fopen($file'r');
    $contents fread($fhfilesize($file));
    fclose($fh);
    echo 
    $contents;
    //outputs: "today is a green day" 
    yes, it cuts the "<new> " with the space :|

    how can i read the html tags?
    :. -= | Eran | =- .:
    __________________

  • #2
    Regular Coder seco's Avatar
    Join Date
    Nov 2008
    Location
    Oregon
    Posts
    687
    Thanks
    6
    Thanked 79 Times in 77 Posts
    try this
    PHP Code:
    echo htmlentities($contents); 
    or look into php html functions
    Last edited by seco; 10-08-2009 at 09:24 PM.

  • Users who have thanked seco for this post:

    Eran (10-08-2009)

  • #3
    New Coder
    Join Date
    Oct 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $file='data.txt';
    $fh fopen($file'r');
    $contents fread($fhfilesize($file));
    fclose($fh);
    echo 
    htmlspecialchars($contents); 
    that may work, i'm not a great coder so there is probably a better way! (UPDATED)

  • #4
    Regular Coder
    Join Date
    Apr 2009
    Location
    somewhere over the rainbow
    Posts
    105
    Thanks
    2
    Thanked 14 Times in 14 Posts
    ohh yes you right! silly me
    i was confused because i saw its ok on the txt file...

    thanks
    :. -= | Eran | =- .:
    __________________

  • #5
    New Coder
    Join Date
    Oct 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No worries if you mean me, glad i could help.


  •  

    Posting Permissions

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