SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Aug 2001
    Location
    Voorhees, NJ
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    embedding php in htm page

    I have a php script that nicely pulls headlines from an rss feed. The problem is that the script only works on a page with a php extension. How can I get this script to work on a page with an htm extension?? Here's the script I'm using:

    <?php
    $xmlfile = fopen("http://r144.com/freelancejobsnews.rss", "r");
    if(!$xmlfile)die("can't find the specified xml file");
    $readfile = fread($xmlfile ,40000);
    $searchfile = eregi("<item>(.*)</item>", $readfile ,$arrayreg);
    $filechunks = explode("<item>", $arrayreg[0]);
    $count = 11;
    //Replace above line with this to show all headlines: $count = count($filechunks);
    for($i=1 ; $i<=$count-1 ;$i++)
    {
    ereg("<title>(.*)</title>",$filechunks[$i], $title);
    ereg("<link>(.*)</link>",$filechunks[$i], $links);
    echo "<br><li>";
    echo "<a href ='$links[1]'\>$title[1]</a>";
    echo "</li></br>";
    }
    ?>

    Any help greatly appreciated
    Thanks, Rob

  2. #2
    1-800-JMULDER JMulder's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,745
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't =|
    Jeroen Mulder

    w: www.jeroenmulder.com

  3. #3
    SitePoint Member
    Join Date
    Aug 2001
    Location
    Voorhees, NJ
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I can't do it with php can someone tell me how to capture an rss feed on a page with an htm extension?

  4. #4
    SitePoint Evangelist ucahg's Avatar
    Join Date
    Apr 2001
    Location
    Sarnia, Ontario, Canada
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do it.

    Either make an iframe with that source, or use the following code instead:

    PHP Code:
    <?php 
    $xmlfile 
    fopen("http://r144.com/freelancejobsnews.rss""r"); 
    if(!
    $xmlfile)die("can't find the specified xml file"); 
    $readfile fread($xmlfile ,40000); 
    $searchfile eregi("<item>(.*)</item>"$readfile ,$arrayreg); 
    $filechunks explode("<item>"$arrayreg[0]); 
    $count 11
    //Replace above line with this to show all headlines: $count = count($filechunks); 
    for($i=$i<=$count-;$i++) 

    ereg("<title>(.*)</title>",$filechunks[$i], $title); 
    ereg("<link>(.*)</link>",$filechunks[$i], $links); 
    echo 
    "document.write(\"<br><li>\")"
    echo 
    "document.write(\"<a href ='$links[1]'\>" addslashes($title[1]) . "</a>\");"
    echo 
    "document.write(\"</li></br>\")"

    ?>
    Then to embed it, add the following code to your main page:
    Code:
    <SCRIPT src="url.to/file.php"></SCRIPT>

  5. #5
    SitePoint Member
    Join Date
    Aug 2001
    Location
    Voorhees, NJ
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code you offered yielded a blank page. Does it need to be adjusted in some way?

    The php file is located at
    http://weblogisticspro.com/fjnphp.php

    It is embedded at
    http://weblogisticspro.com/fjnphp.htm

    Thanks

  6. #6
    SitePoint Member
    Join Date
    Aug 2001
    Location
    Voorhees, NJ
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried it with an iframe and it worked awesomely! Thanks Ucahg for the suggestion

    Rob

  7. #7
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are on an Apache server you can put the following in a .htaccess file so that .htm files will be parsed by the server:

    AddType application/x-httpd-php .htm

    The problem with this is it will pass all .htm files whether they include PHP code or not

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  8. #8
    1-800-JMULDER JMulder's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,745
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Rob144
    I tried it with an iframe and it worked awesomely! Thanks Ucahg for the suggestion

    Rob
    Ugh..iFrames, didn't think of that because if there's one thing I dislike, that's really huge bananas thrown at you by wannabe-monkeys..and iFrames too yes
    Jeroen Mulder

    w: www.jeroenmulder.com


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
  •