Whoa! Crazy!

[code]neak11.30.2003titlecomment../visual/color/0.jpg[/code]
Above is what the file color.etf has in it. Basically, what I'm doing is making a gallery system. All it does at the moment is uploads the image, and writes the information about it to a text file (including the location of the image.) The problem I'm having is with reading the information. It may look odd, but really it's just information I typed using a form, separated by [red][/red]'s, then every line separated by an [red][/red].
I used two explodes after reading the information from the file, one for the lines and one for the parts. Then, at the end, it echos a few things... but for some reason nothing shows up. Does anyone have an idea why?
Here's the code:
[code]
# Top of the page
echo '';

# Fopen the file
$fopened = fopen("../visual/color.etf","r");

# Fread it
$fread = fread($fopened, filesize("../visual/color.etf"));

# Explode, twice... once for the lines and once for the parts
$exploded = explode($fread,"");
$counted = count($exploded);
$number = 0;

# t3h friggin' crazy while loop
while ($number < $counted)
{
$exploded[$number] = explode($exploded[$number],"");
$number++;
}

# Echo...
echo $exploded[$number],$exploded[1][1],$exploded[1],$exploded[$number][1];
[/code]

Comments

  • You switched the parameters for explode()! Here's a slightly easier way to do it:
    [code]
    <?php
    $filehd = fopen ('color.etf', 'r');
    $data = fread ($filehd, filesize ('color.etf'));

    $lines = explode ("", $data);
    array_pop ($lines); // get rid of empty element

    foreach ($lines as $index => $line)
    $lines[$index] = explode ("", $line);

    echo '
    ';                      // print the results
    print_r ($lines);
    echo '
    ';
    ?>
    [/code]
    Or better still - use a database!
  • : Or better still - use a database!

    I was originally using a database. I had a problem that I couldn't fix, so I redid it using text files...

  • And thanks for the help... ^^;
  • [b][red]This message was edited by Neak at 2003-12-1 20:25:24[/red][/b][hr]
    [b][red]This message was edited by Neak at 2003-12-1 20:23:4[/red][/b][hr]
    Alright, here it goes. I did hwat you said and stuff... it looks like it's working... This is the code:
    [code]
    # Top of the page
    echo '';

    # Fopen the file
    $fopened = fopen("../visual/color.etf","r");

    # Fread it
    $fread = fread($fopened, filesize("../visual/color.etf"));

    # Explode, twice... once for the lines and once for the parts

    # First Explosion
    $exploded = explode("
    ", $fread);

    # Get rid of empty part
    array_pop ($exploded);

    # t3h friggin' crazy foreach loop
    foreach ($exploded as $index => $line)
    {
    $exploded[$index] = explode ("", $line);
    }

    echo "
    ";
    print_r ($exploded);
    echo "
    ";
    [/code]

    The problem is that this is what it prints...
    [b]
    Array
    (
    ....[0] => Array
    ........(
    ............[0] => neak
    ............[1] => 12.01.2003
    ............[2] => 123
    ............[3] => 123
    ............[4] => ../visual/color/1.jpg
    ........)

    ....[1] => Array
    ........(
    ............[0] => neak
    ............[1] => 11.30.2003
    ............[2] => title
    ............[3] => comment
    ............[4] => ../visual/color/0.jpg
    ........)

    ....[red][/blue][neak12.01.2003123123../visual/color/1.jpg] => Array
    ........(
    ............[0] => Array
    ........)

    ....[red][/blue][neak11.30.2003titlecomment../visual/color/0.jpg] => Array
    ........(
    ............[0] => Array
    ........)

    )
    [/b]
    I'm only concerned with the last 2 parts(where I added the arrows)... I was wondering why it adds those? Also... The periods are just to keep the organized-ness... :D




  • [b][red]This message was edited by Johnny13 at 2003-12-1 21:17:18[/red][/b][hr]
    heh quite similar to what I usually do..
    but you should use '[red]|[/red]'(OR) instead of 'D',avoid confuse with characters.

    oh regarding your problem,print_r is supposed to show all keys and elements,so you might have to extract info from the array.
  • Why use | rather than ... It seems that a hard-to-type ascii thing would be less used in something like that than a |...
  • : Why use | rather than ... It seems that a hard-to-type ascii thing would be less used in something like that than a |...
    :
    Because | has become a standard delimitor and it is quite easy to debug by typing | rather than with by typing Alt-????.
    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

  • : The problem is that this is what it prints...
    : [b]
    : Array
    : (
    : ....[0] => Array
    : ........(
    : ............[0] => neak
    : ............[1] => 12.01.2003
    : ............[2] => 123
    : ............[3] => 123
    : ............[4] => ../visual/color/1.jpg
    : ........)
    :
    : ....[1] => Array
    : ........(
    : ............[0] => neak
    : ............[1] => 11.30.2003
    : ............[2] => title
    : ............[3] => comment
    : ............[4] => ../visual/color/0.jpg
    : ........)
    :
    : ....[red][/blue][neak12.01.2003123123../visual/color/1.jpg] => Array
    : ........(
    : ............[0] => Array
    : ........)
    :
    : ....[red][/blue][neak11.30.2003titlecomment../visual/color/0.jpg] => Array
    : ........(
    : ............[0] => Array
    : ........)
    :
    : )
    : [/b]
    :

    What exactly does the text file contain?
  • : What exactly does the text file contain?
    :

    The text file contains only this:

    [code]
    neak12.01.2003123123../visual/color/1.jpg
    neak11.30.2003titlecomment../visual/color/0.jpg
    [/code]
  • : : Why use | rather than ... It seems that a hard-to-type ascii thing would be less used in something like that than a |...
    : :
    : Because | has become a standard delimitor and it is quite easy to debug by typing | rather than with by typing Alt-????.
    : [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]
    :
    :
    I believe Neak used that funky D because it was very unlikely to be used while typing a message to be recorded in the file. Why didn't he use a non-displayable character? I believe its because they either don't appear, appear as a generic-box character, or they cause some problem when used.
    __ __ __ __ __ __ __ __
    http://www.exirpt.com
    Just go there!


  • : : : Why use | rather than ... It seems that a hard-to-type ascii thing would be less used in something like that than a |...
    : : :
    : : Because | has become a standard delimitor and it is quite easy to debug by typing | rather than with by typing Alt-????.
    : : [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]
    : :
    : :
    : I believe Neak used that funky D because it was very unlikely to be used while typing a message to be recorded in the file. Why didn't he use a non-displayable character? I believe its because they either don't appear, appear as a generic-box character, or they cause some problem when used.

    [red]
    he could use chr(255), it's untypeable! :-D or isn't chr a php function??? ah well, there is a similar function!
    [/red]
    : __ __ __ __ __ __ __ __
    : http://www.exirpt.com
    : Just go there!
    :
    :
    :

    [size=5][italic][blue]Dar[RED]Q[/RED][/blue][/italic][/size]
    url--> http://mark.space.servehttp.com

  • : The text file contains only this:
    :
    : [code]
    : neak12.01.2003123123../visual/color/1.jpg
    : neak11.30.2003titlecomment../visual/color/0.jpg
    : [/code]
    :

    That's odd - I suspected that's what it contained, but when I copied & pasted your code it worked fine for me!
  • : : The text file contains only this:
    : :
    : : [code]
    : : neak12.01.2003123123../visual/color/1.jpg
    : : neak11.30.2003titlecomment../visual/color/0.jpg
    : : [/code]
    : :
    :
    : That's odd - I suspected that's what it contained, but when I copied & pasted your code it worked fine for me!
    :
    Hmmm. I re-uploaded the file, and now it works fine. It seems that my FTP program must have had an error and not been able to send it, so the script I gave you wasn't the one being used. But, it wroks... :D Thanks.
  • : [code]neak11.30.2003titlecomment../visual/color/0.jpg[/code]
    : Above is what the file color.etf has in it. Basically, what I'm doing is making a gallery system. All it does at the moment is uploads the image, and writes the information about it to a text file (including the location of the image.) The problem I'm having is with reading the information. It may look odd, but really it's just information I typed using a form, separated by [red][/red]'s, then every line separated by an [red][/red].
    : I used two explodes after reading the information from the file, one for the lines and one for the parts. Then, at the end, it echos a few things... but for some reason nothing shows up. Does anyone have an idea why?
    : Here's the code:
    : [code]
    : # Top of the page
    : echo '';
    :
    : # Fopen the file
    : $fopened = fopen("../visual/color.etf","r");
    :
    : # Fread it
    : $fread = fread($fopened, filesize("../visual/color.etf"));
    :
    : # Explode, twice... once for the lines and once for the parts
    : $exploded = explode($fread,"");
    : $counted = count($exploded);
    : $number = 0;
    :
    : # t3h friggin' crazy while loop
    : while ($number < $counted)
    : {
    : $exploded[$number] = explode($exploded[$number],"");
    : $number++;
    : }
    :
    : # Echo...
    : echo $exploded[$number],$exploded[1][1],$exploded[1],$exploded[$number][1];
    : [/code]
    :
    you must assign all of the elements of the array to seperate variables for them to echo. I have tried stuff like that before. it is the same if you do any of the following:
    [code]
    $string = "Hi there, $_SESSION['dude']!';
    echo "Hi there, $_SESSION['dude']!";
    [/code]

    [red]turbo[/red][white]_[/white][blue]eagle[/blue]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories