SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Whats wrong with this code?

    Could someone tell me whats wrong with this code? It doesnt seem to be working and isnt poping up any error either

    PHP Code:
    <?
        
    function getLinks($url) {
            if(!
    $url) {
                return 
    "Error opening $url";
                }
            else {
                
    $url eregi_replace("http://"""$url);
                
    $fp fsockopen("$url"80, &$errorstr, &$errorno30) or DIE("could not connect $errorstr
    (
    $errorno)");
                
    fputs ($fp"GET / HTTP/1.0\r\n\r\n");
                    if(
    $fp) {
                        while(!
    feof($fp)) {
                            
    $data .= fgets($fp4096);
                                            }
                        
    fclose($fp);
                            }
                    else {
                        return 
    "Error opening $url";
                        }
                }
    preg_match_all ("/<a[^>]*>(.+)<\/a>/imU"$data$matches);
            
    $matches $data;
            return 
    $matches;
            }

        
    $links getLinks("www.yahoo.com");
        for (
    $i=0;$i<count($links);$i++) {
                    echo 
    "$links[$i]<br>";
                                            }

    ?>
    i dunno...

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What isn't working with it. I just tested it and it showed me links from yahoo's website. Is there a specific part that isn't working.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    :) delemtri's Avatar
    Join Date
    Jun 2001
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try $link="$links[$i]<br>"; echo "$link"; at the end. I've had problems with trying to echo() array elements before.

  4. #4
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it only shows me an "H" and nothng else
    i dunno...

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now I know you changed some stuff around in your code from the original. I know since I wrote it and it looks different from what you have here. Anyways, not sure where or why the changes were made but it should look like this.

    Code:
    <?
        function getLinks($url) {
            if(!$url) {
                return "Error opening $url";
                }
            else {
                $url = eregi_replace("http://", "", $url);
                $fp = fsockopen("$url", 80, &$errorstr, &$errorno, 30) or DIE("could not connect $errorstr
    ($errorno)");
                fputs ($fp, "GET / HTTP/1.0\r\n\r\n");
                    if($fp) {
                        while(!feof($fp)) {
                            $data .= fgets($fp, 4096);
                                            }
                        fclose($fp);
                            }
                    else {
                        return "Error opening $url";
                        }
                }
    preg_match_all ("/((<a[^>]+>)([^<]+)(<\/a>))/i", $data, $matches);
            return $matches[0];
            }
    
        $links = getLinks("www.yahoo.com");
        for ($i=0;$i<count($links);$i++) {
                    echo htmlspecialchars($links[$i])."<br>";
                                            }
    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yea.. its the code you gave me

    I just changed the for loop and the preg_match_all code.. thats about it..


    hmm.. your code deosnt output anything for me

    All i wanna do is show everything in the <a> </a> tags..
    i dunno...

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is not the code I gave you

    Code:
    preg_match_all ("/<a[^>]*>(.+)</a>/imU", $data, $matches);
            $matches = $data;

    Anyways, not sure why it isn't working for you here it is working as prescribed.

    Working Example
    http://www.irq11.com/freddy/preg_match_all.php

    Source Code for working example
    http://www.irq11.com/freddy/preg_match_all.phps
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    man.. this is unbelievable... now this code is working.. all i did was copy the code from the link you gave me.. made a couple of changes.. and boom.. its working fine


    well thanks a lot for the help
    i dunno...


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
  •