SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Non-Member
    Join Date
    Dec 2004
    Location
    London
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    adding code to a given html file?

    hey, nice forums-
    I was wondering if anyone could tell me if there is a way to add a line of code to the bottom of a given html file (through php?) It's making my head hurt...
    Thanks a lot

  2. #2
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure exactly what you're trying to do, but you can mix PHP and HTML code like this, for example:

    Code:
    <html>
    <head>
    <title><?php $page_title ?></title>
    Of course, what I've shown is in the middle of the code. The point though is to have the starting <?php to start your PHP and have the ?> to end it.

    Hope this helps.

    BTW, welcome to the forums!
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  3. #3
    Non-Member
    Join Date
    Dec 2004
    Location
    London
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for trying, but thats not what I am trying to do.
    Here's an example:
    say I have www.example.com/htmlfile.html. Is there a way that I could add a line of code to the bottom of htmlfile.html? For example, if this was htmlfile.html's source:
    Code:
    <html>
    Hello world!
    </html>
    It would change it to:
    Code:
    <html>
    Hello world!
    </html>
    Here is the added text

  4. #4
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess I'm a little confused as to what you're trying to do. Do you want your PHP script to read the source for a web page and based on the text within certain HTML tags, display a particular text right after that?
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  5. #5
    Non-Member
    Join Date
    Dec 2004
    Location
    London
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vinyl-junkie
    I guess I'm a little confused as to what you're trying to do. Do you want your PHP script to read the source for a web page and based on the text within certain HTML tags, display a particular text right after that?
    no, what it would do is get the source of a file, and add a line of code to that file. For example, it would change:
    Code:
    <html>
    Hello world!
    </html>
    to:
    Code:
    Code:
    
    <html>
    Hello world!
    </html>
    Here is the added text
    and replace the new file with the old one.

  6. #6
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Madison, WI
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $fileloc='/path/to/file.ext'// the path to the file you want to edit
    $file=file_get_contents($fileloc); // change the file into a string
    $file.='Text you want to add.'// append some text to the end of the string
    $r=fopen($fileloc'w'); // open the file for editing
    fputs($r$file); // put your new stuff (the old file + the new text) into the file
    fclose($r); // close the file 

  7. #7
    Non-Member
    Join Date
    Dec 2004
    Location
    London
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh it worked! Thanks a lot!


Bookmarks

Posting Permissions

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