SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help for echo function needed

    Hi, Hello, i'm completely new to PHP and was trying to configure a simple script that is used to validate the existence of a link to my site, from a user inputted URL, kinda like a reciprocal link checker.


    heres the part of the code thats the problem





    Code PHP:
              echo "<b>Links:</b><br>\n"; 
                    if ($is_href) { 
                        foreach ($links as $myval) { 
                            echo "Link: ".$myval."<br>\n";
                            }

    Currently, the code lists ALL the outgoing links on the user inputted URL. So how can i make the echo to not show all the links on that site? Instead of listing all the available links, how to create a hidden 'echo' or 'print' of some sort?

    (I wanted to put the entire script here but Sitepoint doesnt allow links in the codes)

    I want it to not display anything at all, but the echo "Link : "$.myval." " has to be there for the preg_match fucntion towards the end of the script to work. Thanks, i've been racking my brains trying solve it with php and even html, but no cigar. Thanks for the help.

  2. #2
    SitePoint Addict silentcollision's Avatar
    Join Date
    Jun 2006
    Location
    New Zealand
    Posts
    388
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dudewtf View Post
    Currently, the code lists ALL the outgoing links on the user inputted URL. So how can i make the echo to not show all the links on that site? Instead of listing all the available links, how to create a hidden 'echo' or 'print' of some sort?

    (I wanted to put the entire script here but Sitepoint doesnt allow links in the codes)

    I want it to not display anything at all, but the echo "Link : "$.myval." " has to be there for the preg_match fucntion towards the end of the script to work. Thanks, i've been racking my brains trying solve it with php and even html, but no cigar. Thanks for the help.
    So you still want the $myval to be available, but don't want it to be echoed? Why can't you just use the $links array?

    Paste the whole code here regardless of urls. If you can't post because of your limit, run a find/replace for the http and change it to something else temporarily.

  3. #3
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the quick rep, heres the code, i've substituted all http with hxxp



    Code PHP:
     
     
     
     
     
     
     
     
     
     
    <?php 
    // php code example: find links in an html page 
    //  2006 gpl 
    echo "<HTML><HEAD><TITLE>Find links</TITLE></HEAD> \n"; 
    echo "<BODY bgcolor=\"#336699\" text=\"000000\" link=\"#416D96\" vlink=\"#414141\" alink=\"#DDCEA2\"> \n"; 
    echo "<form method=post action=\"$PHP_SELF\"> \n"; 
    echo "<p><table align=\"absmiddle\" width=\"100%\" bgcolor=\"#ededed\" name=\"tablesiteopen\" border=\"0\">\n"; 
    echo "<tr><td align=left>"; 
    if ($_POST["FindLinks"]) { 
            $urlname = trim($_POST["urlname"]); 
            if ($urlname == "") { 
                echo "Please enter a urlname. <br>\n"; 
                } 
            else { // open the html page and parse it 
     
                $page_title = "n/a"; 
                $links[0] = "n/a"; 
                //$meta_descr = "n/a"; 
                //$meta_keywd = "n/a"; 
     
                if ($handle = @fopen($urlname, "r")) { // must be able to read it 
                    $content = ""; 
                    while (!feof($handle)) { 
                        $part = fread($handle, 1024); 
                        $content .= $part; 
                        // if (eregi("</head>", $part)) break; 
                        } 
                    fclose($handle); 
                    $lines = preg_split("/\r?\n|\r/", $content); // turn the content into rows 
     
                        // boolean 
                    $is_title = false; 
                    //$is_descr = false; 
                    //$is_keywd = false; 
                    $is_href = false;                      
                        $index = 0; 
     
                    //$close_tag = ($xhtml) ? " />" : ">"; // new in ver. 1.01 
                    foreach ($lines as $val) { 
                        if (eregi("<title>(.*)</title>", $val, $title)) { 
                            $page_title = $title[1]; 
                            $is_title = true; 
                            } 
                                if (eregi("<a href=(.*)</a>", $val, $alink)) {      
     
                                  $newurl = $alink[1]; 
                                        $newurl = eregi_replace(' target="_blank"', "", $newurl); 
                                        $newurl = trim($newurl); 
                                        $pos1 = strpos($newurl, "/>");                        
                                        if ($pos1 !== false) { 
                                                $newurl = substr($newurl, 1, $pos1); 
                                                } 
                                        $pos2 = strpos($newurl, ">");                        
                                        if ($pos2 !== false) { 
                                                $newurl = substr($newurl, 1, $pos2); 
                                                } 
                                        $newurl = eregi_replace("\"", "", $newurl); 
                                        $newurl = eregi_replace(">", "", $newurl); 
     
                                        //if (!eregi("hxxp", $newurl)) { // local 
                                            //    $newurl = "hxxp://".$_SERVER["hxxp_HOST"]."/".$newurl; 
                                        //    } 
                                        if (!eregi("hxxp", $newurl)) { // local 
                                                $pos1 = strpos($newurl, "/");                        
                                                if ($pos1 == 0) { 
                                                    $newurl = substr($newurl, 1); 
                                                } 
                                                $newurl = $urlname.$newurl; 
                                            }                                
     
                                        // put in array of found links 
                                        $links[$index] = $newurl; 
                                        $index++; 
                                  $is_href = true; 
     
                                } 
     
                        } // foreach lines done 
     
                    echo "<p><b>Page Summary</b><br>\n"; 
                    echo "<b>Url:</b> ".$urlname."<br>\n"; 
                    if ($is_title) { 
                        echo "<b>Title:</b> ".$page_title."<br>\n"; 
                        } 
                    else { 
                        echo "No title found<br>\n"; 
                        } 
                    echo "<b>Links:</b><br>\n"; 
                    if ($is_href) { 
                        foreach ($links as $myval) { 
                            echo "Link: ".$myval."<br>\n";
                            } 
                        } 
                    else { 
                        echo "No links found<br>\n"; 
                        } 
                    echo "End</p>\n"; 
                    } // fopen handle ok 
            else { 
                echo "<br>The url $urlname does not exist or there was an fopen error.<br>"; 
                }    
            echo "Press the back button to try again.<br>"; 
            } // end else urlname given 
        } // else find links now submit 
    else { 
        $urlname = "hxxp://"; // or whatever page you like 
        echo "<p><b>findlinks.php example</b><br>\n"; 
        echo "File or URL: <input type=\"TEXT\" name=\"urlname\" value=\"$urlname\" maxlength=\"255\" size=\"80\"><br>\n"; 
        echo "<input type=\"SUBMIT\" name=\"FindLinks\" value=\"Find\"></font><br></p> \n"; 
        } 
     
     
    //THE SCRIPT I ADDED
                    if (preg_match("/im-fix.com/i", "$myval")) {
                       $imfix = "available";    
                     }
     
    					  	else {
                   $imfix = "unavailable";
                       }
     
     
     
     
                 //THE SCRIPT I ADDED
    if ($imfix == "available") {
         echo " <font color='green'>Link Found</font>";
    }    else if ($imfix == "unavailable") {
         echo " <font color='red'>Please type your URL which links to us</font>";
    }  
    //asdfasdfasdfasdfadfadfasdfasdfadfasdfasdfasdfasdfadsfasdfasdffasdf
     
     
     
     
    echo "</td></tr>"; 
    echo "</table></p>"; 
    echo "</form></BODY></HTML>\n"; 
     
    ?>

  4. #4
    SitePoint Addict silentcollision's Avatar
    Join Date
    Jun 2006
    Location
    New Zealand
    Posts
    388
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've had a quick look, and I don't really understand the logic of the script.

    As far as I can see though, it just uses the last value from the foreach loop.

    In that case you can just use

    PHP Code:
    if (preg_match("/im-fix.com/i"max($links))) {
    $imfix "available";   

    But I'm not sure thats how it supposed to work.

    Edit:

    Or you could just comment out the echo, and leave the foreach loop, but the above comment still stands

  5. #5
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks man, i solved it by emptying everything between the quotation marks in echo " "


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
  •