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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: help with php

  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Location
    Jackson, Georgia
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb help with php

    I need to know how to store contents of a file (page count) into a variable so i can print it anywhere on the page.
    Designers Toolz Admin

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $content implode(''file('filename.txt'));
    print 
    $content
    BTW, please use a more descriptive thread title next time. Thanks.
    De gustibus non est disputandum.

  • #3
    Regular Coder
    Join Date
    Jan 2004
    Location
    Georgia
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey this is dodgerida67....that didnt work.....it just prints:

    Resource id #4

    ~Designer's Toolz~

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Create a file named 'foo.txt'. Write the string "foobar" into it. Put it in the same directory as the script. Run the script and if the file was readable, you will see "foobar" printed out.

    My guess is that you changed the code I gave you and that no longer works, but it's really hard to say without seeing what code you're actually using.
    De gustibus non est disputandum.

  • #5
    New to the CF scene
    Join Date
    Jan 2004
    Location
    Jackson, Georgia
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok heres the deal, im making a forum and that code is part of a 200 line php script i wrote, i need it to print the contents of a document into fput(" ")


    please help
    Designers Toolz Admin

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hard it is to give an answer if code we can not see, young Jedi.

    Just post the relevant part around the fputs() call.
    De gustibus non est disputandum.

  • #7
    Regular Coder
    Join Date
    Jan 2004
    Location
    Georgia
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <?php
    //Get Data From Form
    $username = "$username";
    $email = "$email";
    $postsubject = "$postsubject";
    //Open File
    $data = fopen("log.txt", "a");
    //get replies count
    $count = fopen("$username$postsubject.txt", "w+");
    $content = implode('', file('last$postsubject.txt'));
    //Write Form Data To file
    fputs($data, "<link rel='stylesheet' href='http://64.141.105.108/forum/forum.css' type='text/css'><tr><td bgcolor='f9f9f9'><a href='$username$postsubject.php'>$postsubject</a></td><td bgcolor='#f9f9f9'><a href='mailto:$email'>$username</a></a></td><td>$count</td><td> $month $day, $year</td><td>$content</td></tr>");
    //Close Files
    fclose($count);
    fclose($lastpost);
    fclose($data);
    ?>
    ~Designer's Toolz~

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Inside single quotes, variables don't get expanded. You need to change this line

    PHP Code:
    $content implode(''file('last$postsubject.txt')); 
    to

    PHP Code:
    $content implode(''file("last$postsubject.txt")); 
    After that, the content gets written by fputs() into the other file. If there still appears a "Resource ID" string, that's due to the variable $count, which points to an open file.
    De gustibus non est disputandum.

  • #9
    Regular Coder
    Join Date
    Jan 2004
    Location
    Georgia
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    now i get...


    Warning: file(lastgdsgdfg.txt): failed to open stream: No such file or directory in /var/www/html/forum/php/phppostprocessor.php on line 46

    Warning: implode(): Bad arguments. in /var/www/html/forum/php/phppostprocessor.php on line 46

    Warning: fclose(): supplied argument is not a valid stream resource in /var/www/html/forum/php/phppostprocessor.php on line 51



    looks like all of this is because file doesnt exist. I need it to create the file if it doesnt exist, now what?
    ~Designer's Toolz~

  • #10
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can check with file_exists() if, uhm, the file exists, and if that's not the case, create it with fopen().
    De gustibus non est disputandum.

  • #11
    Regular Coder
    Join Date
    Jan 2004
    Location
    Georgia
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry, that was basic stuff. anyway it still shows resource id...what now? and thanks for your help
    ~Designer's Toolz~

  • #12
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    I don't want to sound really harsh here, but this is rather basic ... how are you making a forum if you can't make a counter?

    I'm just saying don't bite off more than you can chew ... it will only lead to disappointment (well on one hand, experience on the other)..
    Omnis mico antequam dominus Spookster!

  • #13
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't know what you mean with the Resource Id, because... you did not include any sample code which shows this behaviour. Again. And judging from your posts I think your script is under heavy development, so there is not point in guessing where your error might be if one doesn't know the code in use right now.

    Following up on Mhtmls post, perhaps you first sit down and make a plan how your script should work, what features it should have, and in what components and stages it would be dividable. Do that process with pen and paper, and be not afraid to draw funky diagrams with a lot of comments and blurry lines connecting each shape to each other. That will help you get a mental model of what you actually are going to do, and the best part - you have it documented on paper, so you can easily adjust the diagram if the need arises.

    The next step would be to prototype what you have on paper in PHP. Just think about the interfaces and how you would structure the files involved. Try to define the smallest units of work to do and write a blank function for that. An example for a very small unit would be: Increment a counter variable stored in a textfile.

    Next, implement those units. This stage helps you to concentrate on the coding of the individual parts. Make them run as stand-alone units, and wire them together at a later stage, or you end up in the Big Ball of Mud you currently have.

    And of course, for detailed questions about some nasty PHP code, consult this forum... and don't forget to post sample code!
    De gustibus non est disputandum.

  • #14
    Regular Coder
    Join Date
    Jan 2004
    Location
    Georgia
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Mhtml, these forums were designed to help people and become a huge resourse. Not to downplay people and there skills. If you never get into anything then you will never learn anything. I am new to php but have a good history with lots of other programing language. If it is so basic why didnt you post an answer instead of chewing on me like that? If your not going to help please dont bother to post.



    And yes, I can make a counter and have made plently. The trouble if you had read carefully is in displaying this counter. Not creating one.


    This is over a 200 line php script and I have written every character but I need help with this because it is giving me trouble and I realy dont know why because like I said I am fairly new to PHP. And noone knows everything about one programing language, we all forget things about it here and there, its human nature. And we all have to look at a reference every now and then noone can deny that. And theres not a thing wrong with it. and that is what exsacly I am doing here with this forum and that is what it was intendedly created for.




    And for you, mordred, I want to thank you for your help. Ill post the script up asap so you can have a look. Thanks
    Last edited by DsgnrsTLZAdmin; 01-15-2004 at 10:43 PM.
    ~Designer's Toolz~

  • #15
    Regular Coder
    Join Date
    Jan 2004
    Location
    Georgia
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this is what returns "Resource ID" ($content)




    <?php
    //Get Data From Form
    $username = "$username";
    $email = "$email";
    $postsubject = "$postsubject";
    //Open File
    $data = fopen("log.txt", "a");
    //get replies count
    $count = fopen("$username$postsubject.txt", "w+");
    $create = fopen("last$postsubject.txt", "w+");
    $content = implode('', file("last$postsubject.txt"));
    //Write Form Data To file
    fputs($data, "<link rel='stylesheet' href='http://64.141.105.108/forum/forum.css' type='text/css'><tr><td bgcolor='f9f9f9'><a href='$username$postsubject.php'>$postsubject</a></td><td bgcolor='#f9f9f9'><a href='mailto:$email'>$username</a></a></td><td>$count</td><td> $month $day, $year</td><td>$content</td></tr>");
    //Close Files
    ?>
    ~Designer's Toolz~


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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