Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: earn 100 credits for helping me (topic-php)

  1. #1
    nahsorhseda's Avatar
    nahsorhseda is offline x10 Sophmore nahsorhseda is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    mumbai
    Posts
    116

    earn 100 credits for helping me (topic-php)

    i want a php search script in which it will find only the links and not the text .......i want the search to specify only the results from the pages i specify

    i want this script because i have a lot of html files which have links to different media files and are hosted at a different hosts

    so i want a search so that people can find direct links to the file when they search
    glad to resolve problems in c++ n php

  2. #2
    Slothie's Avatar
    Slothie is offline Lord Of The Keys Slothie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Singapore
    Posts
    1,432

    Re: earn 100 credits for helping me (topic-php)

    ??????

    That's not very specific. Search links from where?

    Easiest 70 points you'll make on x10

    Feel free to add my reputation by clicking on the if you found my post helpful to you :P


    If I am not responding to your PMs, that means I am ignoring you. Take a hint.



    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


  3. #3
    mattura's Avatar
    mattura is offline x10 Elder mattura is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    563

    Re: earn 100 credits for helping me (topic-php)

    I think you mean a regex expression to search raw html for links, something like this:

    <?php
    $rawhtml="<body><h1>Heading</h1><h3>The <a href='www.google.com'>link</a> goes to google</h3><h2>but <a href='nowhere.org' class='link'>this</a> doesn't</h2></body>"; //example
    $pattern="|<a.*?>.*?</a>|";
    if (preg_match_all($pattern, $rawhtml, $match)) { //if match:
    //list matches or whatever: $matches[0][0], $matches[0][1] etc
    }
    ?>
    Edit:
    ----

    Here is something a bit better:

    <?php
    $rawhtml='<body><h1>Heading</h1><h3>The <a href="http://www.google.com">link</a> goes to google</h3><h2>and <a class="link" href="http://second.com">this one</a> goes elsewhere!</h2><a id="id" class="heavy" href="http://www.large.com" name="what?" attr="nowt">big</a></body>'; //example
    $pattern='!(<a(.*?)?href=("|\')(.*?)("|\')(.*?)>(. *?)</a>)!';

    echo "String:<br/><textarea name='raw' rows='5' cols='100'>$rawhtml</textarea><br/>";
    echo "Pattern:<textarea rows='1' cols='90'>$pattern</textarea><br/>";

    if (preg_match_all($pattern, $rawhtml, $match)) {
    echo "Result:<br/>";
    echo "<table border='1' cellpadding='3px'> <tr><td>Title</td><td>Link</td><td>Attributes</td></tr>";
    foreach($match as $k=>$v) {
    echo "<tr><td>".$match[7][$k]."</td><td><a href='".$match[4][$k]."'>".$match[4][$k]."</a></td><td>".$match[2][$k].$match[6][$k]."</td></tr>";
    }
    echo "</table><textarea rows='17' cols='100'><br/>Array:";
    print_r($match);
    echo "</textarea>";
    } else {echo "No Match";}
    ?>

    The above will take any html input and output only the link data, in a nice little table, including other attributes if necessary. Try it out! Come on you know that's worth the credits! Took me over an hour to come up with the regex pattern!
    Last edited by mattura; 11-29-2007 at 02:46 PM. Reason: More writing! I'm such a good samaritan
    ----
    Life is a game. The conception is terrible but the graphics are amazing!
    matt.elementfx.com

  4. #4
    Slothie's Avatar
    Slothie is offline Lord Of The Keys Slothie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Singapore
    Posts
    1,432

    Re: earn 100 credits for helping me (topic-php)

    Or you could use something like this
    PHP Code:
    $url "http://www.example.net/somepage.html";
    $input = @file_get_contents($url) or die('Could not access file: $url');
    $regexp "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
    if (
    preg_match_all("/$regexp/siU"$input$matchesPREG_SET_ORDER)) {
        foreach(
    $matches as $match)
        {
            
    $links[] =  $match[2// link addresses
            
    $linktext[] =  $match[3//link text
        
    }

    This will let you parse the links from a remote array and store them all in $links

    Easiest 70 points you'll make on x10

    Feel free to add my reputation by clicking on the if you found my post helpful to you :P


    If I am not responding to your PMs, that means I am ignoring you. Take a hint.



    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


  5. #5
    Slothie's Avatar
    Slothie is offline Lord Of The Keys Slothie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Singapore
    Posts
    1,432

    Re: earn 100 credits for helping me (topic-php)

    OR if you need to parse link from multiple pages

    PHP Code:
    $links = array();
    $linktext = array();

    $urls[] = "http://www.example.net/somepage.html";
    $urls[] = "http://www.example.net/somepage1.html";
    $urls[] = "http://www.example.net/somepage2.html";
    $urls[] = "http://www.example.net/somepage3.html";
    //continue this as much as you want :D

    foreach($urls as $url) {
        
    $input = @file_get_contents($url) or die('Could not access file: $url');
        
    $regexp "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
        if (
    preg_match_all("/$regexp/siU"$input$matchesPREG_SET_ORDER)) {
            foreach(
    $matches as $match)
            {
                
    $links[] =  $match[2// link addresses
                
    $linktext[] =  $match[3//link text
            
    }
        }


    Easiest 70 points you'll make on x10

    Feel free to add my reputation by clicking on the if you found my post helpful to you :P


    If I am not responding to your PMs, that means I am ignoring you. Take a hint.



    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


  6. #6
    nahsorhseda's Avatar
    nahsorhseda is offline x10 Sophmore nahsorhseda is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    mumbai
    Posts
    116

    Re: earn 100 credits for helping me (topic-php)

    i liked slothies idea of i.e i can search many pages at once ..........but it showing me parsing errors

    Parse error: syntax error, unexpected T_VARIABLE in /home/hsedan/public_html/search/s1.php on line 18

    ......please rectify it and ill pay you 100 credits

    to be more specific """ consider i have 2 pages page1.html and page2.html with links to mp3, files i want a search which can search for mp3 links

    but i have over 800 html pages with links to different media files thats why i liked slothies idea

    if you can please add a html form with text input and submit button and please give a complete php code ie starting from "<?php" and ending with"?>" and also it must show 10 results per page ...and next and previous link{25 credits extra for that}


    hope you get your 100 credits.....
    glad to resolve problems in c++ n php

  7. #7
    Slothie's Avatar
    Slothie is offline Lord Of The Keys Slothie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Singapore
    Posts
    1,432

    Re: earn 100 credits for helping me (topic-php)

    PHP Code:
    <?php
    $links 
    = array();
    $linktext = array();

    $urls[] = "http://www.example.net/somepage.html";
    $urls[] = "http://www.example.net/somepage1.html";
    $urls[] = "http://www.example.net/somepage2.html";
    $urls[] = "http://www.example.net/somepage3.html";
    //continue this as much as you want :D

    foreach($urls as $url) {
        
    $input = @file_get_contents($url) or die('Could not access file: $url');
        
    $regexp "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
        if (
    preg_match_all("/$regexp/siU"$input$matchesPREG_SET_ORDER)) {
            foreach(
    $matches as $match)
            {
                
    $links[] =  $match[2]; // link addresses
                
    $linktext[] =  $match[3]; //link text
            
    }
        }
    }  

    ?>
    Forgot to add in ;

    Pagination would be a bit tougher since this is a fairly simple script.

    Easiest 70 points you'll make on x10

    Feel free to add my reputation by clicking on the if you found my post helpful to you :P


    If I am not responding to your PMs, that means I am ignoring you. Take a hint.



    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


  8. #8
    nahsorhseda's Avatar
    nahsorhseda is offline x10 Sophmore nahsorhseda is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    mumbai
    Posts
    116

    Re: earn 100 credits for helping me (topic-php)

    its showing me a blank page ......i did not get any errors
    i really dont know php very well so please make me a html form or atleast tell me what the name of the input should be if u build me the simple html form the 125 credits are all yours
    glad to resolve problems in c++ n php

  9. #9
    GG-Xtreme's Avatar
    GG-Xtreme is offline x10 Lieutenant GG-Xtreme is an unknown quantity at this point
    Join Date
    Aug 2007
    Location
    BIG APPLE
    Posts
    430

    Re: earn 100 credits for helping me (topic-php)

    Would you need PHP intermediate version just for this?

  10. #10
    Slothie's Avatar
    Slothie is offline Lord Of The Keys Slothie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Singapore
    Posts
    1,432

    Re: earn 100 credits for helping me (topic-php)

    PHP Code:
    <?php
    $links 
    = array();
    $linktext = array();

    $urls[] = "http://www.example.net/somepage.html";
    $urls[] = "http://www.example.net/somepage1.html";
    $urls[] = "http://www.example.net/somepage2.html";
    $urls[] = "http://www.example.net/somepage3.html";
    //^-- modify these to fit your sites

    //continue this as much as you want :D

    foreach($urls as $url) {
        
    $input = @file_get_contents($url) or die('Could not access file: $url');
        
    $regexp "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
        if (
    preg_match_all("/$regexp/siU"$input$matchesPREG_SET_ORDER)) {
            foreach(
    $matches as $match)
            {
                
    $links[] =  $match[2]; // link addresses
                
    $linktext[] =  $match[3]; //link text
            
    }
        }
    }  


    ?> 

    <pre>
    <?php
    print_r
    ($links);
    ?>
    It should print out all your links, you'll have to manipulate them yourself. If anyone else wants to extend on this code, feel free to do so.

    Easiest 70 points you'll make on x10

    Feel free to add my reputation by clicking on the if you found my post helpful to you :P


    If I am not responding to your PMs, that means I am ignoring you. Take a hint.



    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


Closed Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  2. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  3. Sigo con problemas con phpbb2
    By reciecho in forum Soporte
    Replies: 7
    Last Post: 10-20-2007, 06:28 PM
  4. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers