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 2 of 2
  1. #1
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    I am trying to find out out dynamically how many links are in a web page's markup, using this code

    PHP Code:
    <?php

    $file 
    '../file1.txt';
    $fo file_get_contents($file);


        function 
    getAnchorsHref$string ) {
            
    $regExMatches = array();
            
    eregi('<a((.+)[[:space:]])href="(.+)"',$string,$regExMatches);
            if(
    count($regExMatches)>1)
                return 
    $regExMatches[2];
            return 
    "nope";
        }

    echo 
    getAnchorsHref($fo);

    ?>
    However I always get "nope" returned, and I know for a fact that file1.txt has 1 valid link inside it (thats all it has).

    The output I would like would be similar to
    http;//domain.org/file.htm (absolute)
    file1.htm (relative).

    Any ideas/better solutions?

  2.  

  3. #2
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Don't know it's any better, but it works.

    PHP Code:
    $file '../file.txt'
    $foo file_get_contents($file); 


    $i=1;
    foreach(
    findRefs($foo) as $link)
    {
        print 
    "<b>Link_$i:</b><i> ".$link."</i><br />";
        
    $i++;
    }


    //function using pregmatch
        
    function findRefs($var)
        { 
            
    preg_match_all("/<a\s+href=\"(.*)\"/"$var$match); 
            
            if(
    count($match[1])>1
                return 
    $match[1]; 
            return 
    "nope"
        } 
    S. Rosland


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 03:01 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com