Text is clipped in textarea

Discussion in 'PHP' started by patter, Dec 29, 2007.

  1. #1
    I'm trying to create a text editor. My basic code is
      if (($fp = file($fullPath)) !== FALSE)
      {
        for ($idx = 0; $idx < count($fp); ++$idx)
        {
           $contents[] = $fp[$idx];
        }
      }
    
    <textarea name="contents" wrap="soft"><?php echo $contents; ?></textarea>
    Code (markup):
    The above works fine until I try it on a line like this:
    I need the output to exatcly match the line read but it only displays up to the closing tag like
    I've tried using htmlentities when the array is created, like below, but it still fails.
    $contents[] = htmlentities($fp[$idx]);
    Code (markup):
    If I echo the line as it is being added to the array, it shows it is being read correctly so the problem seems to be with how the textarea handles the code. Does anyone know how to code this so it displays correctly?
     
    patter, Dec 29, 2007 IP
  2. selling vcc

    selling vcc Peon

    Messages:
    361
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    use htmlspecialchars() instead
     
    selling vcc, Dec 30, 2007 IP
  3. patter

    patter Member

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    Thanks for the suggestion but since htmlspecialchars is just a subset of htmlentities, it fails the same way.
     
    patter, Dec 30, 2007 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    You shouldn't need to use anything. Text like:

    <p class="hdr">Some text here</p>

    should appear fine, even with the tags not encoded (I just tested it on IE/FF).

    There is something else wrong. Upload the script and show us a live link.

    Peace,
     
    Barti1987, Dec 30, 2007 IP
  5. patter

    patter Member

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    Yes, you are correct. It was my mistake. I was preparing a cut-down script that I could post here and realized the code was only reading in one line of text. It was working on some files because they didn't have line breaks in them. I changed the code to account for that and it is working correctly now. I appreciate both of you trying to help. Without it I probably would not have noticed this silly mistake.
     
    patter, Dec 31, 2007 IP