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 9 of 9
  1. #1
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Why is there junk in output?

    Hi gang...
    Once again I am in need of the PHP Gods. Have a look at the code below:
    PHP Code:
    if (is_dir($filename) && (!eregi("_vti_cnf",$filename)) && (!eregi("_overlay",$filename)) && (!eregi("_derived",$filename)) && ($filename!=".") && ($filename!="..")) { 
                    
    $currdir = array(); 
                    
    $gallery opendir($filename); 
                    
    $imgcount 0;  
                    
    $gallerytitle $filename "/gallery.txt";
                     
        
    //loop to count number of images.... 
         
        
    while($f readdir($gallery)){ 
        
           if((
    $f != ".") && ($f != "..")&& (eregi("(\.jpg|\.gif|\.png)$"$f))){ 
                
           
    //get a random image to display.... 
            
           
    array_push($currdir,"$f"); 
           
    $d $currdir[(array_rand($currdir))]; 
           
    $displayimg sprintf($d,s); 
                  
    $imgcount++;  
                } 
            } 
        
    closedir($gallery); 
            
    //If the photo folder has a file named 'gallery.txt'
            //This will read the first line and stick that text
            //into the "alt" of the image (displays on mouseover)
            
            // read title of gallery from gallery.txt
           
        
    if (file_exists($gallerytitle)) { 
        
    $title_file file($gallerytitle); 
        
    $title $title_file[0];
        }
        
    // if no gallery.txt file was found; show user through $title on webpage
        
    else {
         
    $title "No description for this gallery was provided";
         } 
    The first gallery.txt file returns a string no problem, but subsequent strings are preceeded by some junk that looks like "". Each gallery.txt file is a single line of text with no quotes around it or white space. What in the world is causing this, and how do I get rid of it?
    Andy
    (Management+Coworkers)<>Logic

  • #2
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Weird characters are usually the result of character encoding issues (UTF-8 versus [insert your favorite format]).

  • #3
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    ah,
    Ok.
    I used ereg_replace to take out the bizzaro stuff; is that the right way to go about this?
    (Management+Coworkers)<>Logic

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    First, you should be using preg_replace instead of ereg_replace. It is generally better in all aspects.

    Secondly, it would only be a temporary fix in case this is a time critical issue. You would be fixing the symptom, not the cause.

  • #5
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Ok,
    I can change to preg_replace. How/where would I be looking to make an encoding change? And, why would the first one come through ok if the encoding is screwed up? trying to learn....
    (Management+Coworkers)<>Logic

  • #6
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Your gallery.txt is encoded in a certain way, and PHP expects a certain encoding.

    If the results are not always affected, check the source encoding (the text files).

    Otherwise, do some research in how character encoding works in PHP.

    It's also possible that it might be a very obvious issue. But without looking at the setup this is what I can tell you.

    PHP operates in a certain character encoding. And unless you tell it to read something a certain way, it will see it wrong.

  • #7
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Ok Aedrin,
    I'm confused. In gallery.php there is
    Code:
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
    which gives us encoding, right? Where do I find that in a .txt file?

    Andy
    (Management+Coworkers)<>Logic

  • #8
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    PHP doesn't use that encoding.

    That's only for the browser when viewing the page.

    I can't tell you what marks a file with a certain encoding.

  • #9
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    oh,
    OOOOOOOOOOOOOOOOOoooooooooooooooooooooooohhhhhhhhhh!!
    The PHP Encoding! DOH!!
    I get it. Let me take a look at THAT!
    Andy
    (Management+Coworkers)<>Logic


  •  

    Posting Permissions

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