Why does this code leave a space within my html ?

Discussion in 'PHP' started by marcel, May 17, 2006.

  1. #1
    Why does this code leave a space within my html ?

    $domaincats = $thishost . "_domain.txt";
    PHP:
     
    marcel, May 17, 2006 IP
  2. mihaidamianov

    mihaidamianov Well-Known Member

    Messages:
    1,434
    Likes Received:
    111
    Best Answers:
    0
    Trophy Points:
    190
    #2
    where is the space going? before "_domain.txt"?
     
    mihaidamianov, May 17, 2006 IP
  3. marcel

    marcel Well-Known Member

    Messages:
    1,503
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    150
    #3
    it's ends up inside my html
     
    marcel, May 17, 2006 IP
  4. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Where in your html? And how do you echo the variables to the html?
     
    mad4, May 17, 2006 IP
  5. mihaidamianov

    mihaidamianov Well-Known Member

    Messages:
    1,434
    Likes Received:
    111
    Best Answers:
    0
    Trophy Points:
    190
    #5
    Well, from that bit of code I find impossible to tell where the problem is. Maybe if you paste more of it.. Maybe you have redundant spaces around the code..
     
    mihaidamianov, May 17, 2006 IP
  6. marcel

    marcel Well-Known Member

    Messages:
    1,503
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    150
    #6
    This is the full function that keeps creating a blank empty space.



    WHAT THIS CODE DOES:

    It checks to see if a file exists (127.0.0.5_domain.txt), if it exists it loads the file and uses this data. If the file does not exit it fetches data from a database table and creates the file.





     function thisdomaincat($thishost="")
    
    { 
    
    $domaincats = $thishost . "_domain.txt";
    
    if(is_file($domaincats))
    
    {
    
    $thisbranch = file_get_contents("$domaincats"); 
    
    }
    
    else
    
    {
    
    $mypicsql = "SELECT tid FROM custom_categories where domain = '$thishost'";
    
    $sql_result = mysql_query($mypicsql) or die("Couldn't execute query.");
    
    while ($row = mysql_fetch_array($sql_result)) 
    
    {
    
         if($tcount > 0)
    
         {
    
         $thisbranch .= ",$row[tid]";
    
         }
    
         else
    
         {
    
         $thisbranch .= "$row[tid]";     
    
         }
    
         $tcount++;
    
    } 
    
     
    
    $writefile = fopen("$domaincats", 'w');
    
    if (!$writefile)
    
    {
    
        echo "<p>Unable to open temporary file for writing.</p>"; 
    
        echo "Update aborted";
    
        exit(); 
    
    }
    
    else
    
    {
    
        fwrite($writefile,$thisbranch);
    
        fclose($writefile);
    
    } 
    
    }
    
    return $thisbranch;
    
    }
    
    
    PHP:
     
    marcel, May 17, 2006 IP
  7. marcel

    marcel Well-Known Member

    Messages:
    1,503
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    150
    #7
    Thanks for the suggestions so far.

    This works but isn't useful

     
    
    $domaincats = "127.0.0.5" . "_domain.txt";
    
    // I'm only changing domains here 
    
    $domaincats = "127.0.0.4" . "_domain.txt";
    
    
    PHP:


    This does not work ( because of the space), but would be useful

     
    
    $domaincats = trim($thishost) . "_domain.txt";
    
    //or 
    
    $domaincats = "$SERVER[HTTP_HOST]" . "_domain.txt";
    
    
    PHP:
     
    marcel, May 17, 2006 IP
  8. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Not sure where the space is actually being outputted to the screen? Maybe you could use a str_replace.......

    $domaincats= str_replace(" ", "", $domaincats); 
    PHP:
     
    mad4, May 17, 2006 IP
  9. jimrthy

    jimrthy Guest

    Messages:
    283
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Just out of curiousity, let me get this straight. You comment that line of code out, and the space goes away?

    Is the space showing up in the HTML where this function is defined, or when it gets called?
     
    jimrthy, May 18, 2006 IP
  10. JamesColin

    JamesColin Prominent Member

    Messages:
    7,874
    Likes Received:
    164
    Best Answers:
    1
    Trophy Points:
    395
    Digital Goods:
    1
    #10
    it would be much more simple if marcel was showing an example of where the space appears along with the code of the function. As well, how the function is called would be interesting in order to solve the problem.
     
    JamesColin, May 23, 2006 IP