Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: PHP help

  1. #11
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Havent tested it, but try it.

    PHP Code:
    <?php
    $objNum 
    5;

    $file 'Values.plist';

    $string '<?xml version="1.0" encoding="UTF-8"?>';
    $string .= '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">';
    $string .= '<plist version="1.0">';

    $string .= '<dict>';

    for( 
    $i 1$i $objNum$i++ )
    {
        
    $obj $_POST'Object' $i ];
        
    $objX $_POST'Object' $i 'x' ];
        
    $objY $_POST'Object' $i 'y' ];
        
        
    $string '<key>Item' $i '</key>';
        
    $string .= '<string>' $obj '</string>';
        
        
    $string .= '<key>Item' $i 'x</key>';
        
    $string .= '<string>' $objX '</string>';
        
        
    $string .= '<key>Item' $i 'y</key>';
        
    $string .= '<string>' $objY '</string>';
    }

    $string .= '</dict>';

    $handle fopen$file );
    fwrite$handle$string );
    fclose$handle );
    ?>
    Hi, names James. I am a web developer.

  2. #12
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    Quote Originally Posted by Protege View Post
    Havent tested it, but try it.

    PHP Code:
    <?php
    $objNum 
    5;

    $file 'Values.plist';

    $string '<?xml version="1.0" encoding="UTF-8"?>';
    $string .= '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">';
    $string .= '<plist version="1.0">';

    $string .= '<dict>';

    for( 
    $i 1$i $objNum$i++ )
    {
        
    $obj $_POST'Object' $i ];
        
    $objX $_POST'Object' $i 'x' ];
        
    $objY $_POST'Object' $i 'y' ];
        
        
    $string '<key>Item' $i '</key>';
        
    $string .= '<string>' $obj '</string>';
        
        
    $string .= '<key>Item' $i 'x</key>';
        
    $string .= '<string>' $objX '</string>';
        
        
    $string .= '<key>Item' $i 'y</key>';
        
    $string .= '<string>' $objY '</string>';
    }

    $string .= '</dict>';

    $handle fopen$file );
    fwrite$handle$string );
    fclose$handle );
    ?>
    Ya forgot a .

    PHP Code:
    <?php
    $objNum 
    5;

    $file 'Values.plist';

    $string '<?xml version="1.0" encoding="UTF-8"?>';
    $string .= '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">';
    $string .= '<plist version="1.0">';

    $string .= '<dict>';

    for( 
    $i 1$i $objNum$i++ )
    {
        
    $obj $_POST'Object' $i ];
        
    $objX $_POST'Object' $i 'x' ];
        
    $objY $_POST'Object' $i 'y' ];
        
        
    $string .= '<key>Item' $i '</key>';
        
    $string .= '<string>' $obj '</string>';
        
        
    $string .= '<key>Item' $i 'x</key>';
        
    $string .= '<string>' $objX '</string>';
        
        
    $string .= '<key>Item' $i 'y</key>';
        
    $string .= '<string>' $objY '</string>';
    }

    $string .= '</dict>';

    $handle fopen$file );
    fwrite$handle$string );
    fclose$handle );
    ?>

  3. #13
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Woops. Well pointed out.
    Hi, names James. I am a web developer.

  4. #14
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default

    Cheers guys, +REP to all. One more thing is removal. How would I go about doing that?

  5. #15
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default

    I have been given this a potential solution but it doesn't seem to be working. Any help?
    Code:
    <?php 
    $file = file_get_contents('Names.plist');
    $file = explode("\n", $file);
     
    $name = $_POST['Name'];  
     
    foreach($file as $key => $value)
    {
        if(strstr($value, '<string>'.$name.'</string>'))
            unset($file[$key]);
    }
     
    echo implode("\n", $file);
    
    ?>
    Last edited by MrPinkPanther; 07-07-2009 at 12:43 PM.

  6. #16
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default

    Ignore the above post but I'm having trouble getting the code you guys created to work:
    <?php
    $objNum = 5;

    $file = 'Names.plist';

    $string = '<?xml version="1.0" encoding="UTF-8"?>';
    $string .= '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">';
    $string .= '<plist version="1.0">';

    $string .= '<dict>';

    for( $i = 1; $i < $objNum; $i++ )
    {
    $obj = $_POST[ 'Name' . $i ];

    $string = '<key>Name' . $i . '</key>';
    $string .= '<string>' . $obj . '</string>';
    }

    $string .= '</dict>';

    $handle = fopen( $file );
    fwrite( $handle, $string );
    fclose( $handle );
    ?>
    I'm "POST"ing this to it:
    Name1 = George;
    Name2 = Alan;
    Name3 = Bob;
    Name4 = Zach;
    Name5 = Ian;
    But it doesn't work. I added "w" after the FileOpen stuff so it knew to Write to it but then it just overwrites it all. If the "W" isnt there then it doesn't write anything and when you visit its location it says PHP on line 22.
    Last edited by MrPinkPanther; 08-07-2009 at 11:45 AM.

  7. #17
    Join Date
    Apr 2009
    Location
    United Kingdom
    Posts
    1,111
    Tokens
    100

    Latest Awards:

    Default

    Quote Originally Posted by FlyDuo View Post
    Ignore the above post but I'm having trouble getting the code you guys created to work:

    I'm "POST"ing this to it:

    But it doesn't work. I added "w" after the FileOpen stuff so it knew to Write to it but then it just overwrites it all. If the "W" isnt there then it doesn't write anything and when you visit its location it says PHP on line 22.
    Er. Sorry I aint been paying attention to what you want. When you say overwrites it all, do you mean the current stuff in the file? You want to add to the file?

  8. #18
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    Didn't read the post fully, but if you want to add it on the the end of a file, I think you need to fopen it with the 'a' flag - for append.

  9. #19

    Default

    Quote Originally Posted by Source View Post
    Didn't read the post fully, but if you want to add it on the the end of a file, I think you need to fopen it with the 'a' flag - for append.
    This is correct:
    taken from http://uk3.php.net/manual/en/function.fopen.php
    'a' Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
    This should achieve what you are trying to do.

    EDIT: example:
    PHP Code:
    $handle fopen$file'a' );
    fwrite$handle$string );
    fclose$handle ); 

Page 2 of 2 FirstFirst 12

Posting Permissions

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