Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    I am pretty sure this is possible using PHP.

    Lets say page1.html (hosted on another server). On that page there is two <h1> tags, them being spaghetti and cheese.

    Is there a way to get the text in between them?

    I wish to display the text on a page on my server.

    Thanks in advance.

  2.  

  3. #2
    Senior Member
    Join Date
    Aug 2003
    Posts
    444
    Member #
    2801
    Of course it's possible in PHP

    You can use fopen() to open URLs just like files. See http://uk2.php.net/manual/en/function.fopen.php . What you then get back is a lot of text (page1.html) and then you can use regular expressions to fish out the H1 tags.

    This may not work on some (most?) hosts as they disable the ability to use URLs in fopen(). Give it a shot and see what happens.

    If that fails, then one way that will work is to write a PHP script that uses sockets and pretend you are a browser. Request the page as strip out the headers and you will have the HTML. This is complex though but I've seen some tutorials and code scattered around the net.
    eKstreme
    eKstreme.com - Free website tools!
    fontfox - free fonts Hand-picked quality fonts.

  4. #3
    Senior Member Richard S's Avatar
    Join Date
    Jul 2004
    Location
    SW Lonodn
    Posts
    219
    Member #
    6728
    Liked
    3 times
    I did a simalr thing this morning messing around. to get the 5 most 'latest topics' form here:

    http://www.hardwareanalysis.com/cont...latest_topics/

    and display just the titles to the threads on in a table to display on my personal site.

    Heres the result of the code I wrote:

    http://www.rrss.co.uk/fopen4.php

    (needs fomating with css, but it works).

    Heres the php code I used:

    PHP Code:
    <table width="300" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:9px; border:1px dotted black; padding:5px; ">
    <tr><td style="font-weight:bold; ">Latest topics on HWA</td></tr>
    <?php

    $change_url 
    = array('href="/content/' => 'href="http://www.hardwareanalysis.com/content/'); #change link address so they point to HWA and not the page the links are shown on


    $lines file('http://www.hardwareanalysis.com/content/community/latest_topics/'); # open the page as a file


    foreach ($lines as $line_num => $line# go through each line
    {
      if (
    strlen($line) > 12000)            # on the page I'm looking at the list of threads is all on one line, genorated with php with no new line tags.
          
    {
            
    $line strtr($line,$change_url);  #use this fucntion to change the URL, see above
               
    $newline explode("</tr><tr>"$line); #explode the string at the row tags, thus giving each row or thread as a single string
            
            
    while ($i 7
                {
                            if (!
    substr_count($newline[$i], "Sticky:")) # check to see if the thread is a 'sticky' topic, I don't want to display these.
                                
    {
                                    
    $topic explode("<a "$newline[$i]); # explode the string at the '<A' tags
                                    
    echo '<tr><td><a '.$topic[1].'</td></tr>';    #this prints the new row on my own page using just the first entry in the array we just exploded.
                                
    }
                  
    $i++;
                }
        }
    }


    ?>

    </table>
    You may be able to do something simalar, except explode() with '<h1>'.

    It's little messy and I sure I could have done a better job with regular expresions, except they confuse the hell out of me.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 11:38 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com