select and get html script

Discussion in 'PHP' started by ojsimon, Dec 20, 2007.

  1. #1
    Hi
    is it possible to make a script that allows a user to select a portion of a page and extract the html code.

    Thanks
     
    ojsimon, Dec 20, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Generally, yes.

    (This answer is about as specific as your question.)
     
    nico_swd, Dec 20, 2007 IP
  3. ojsimon

    ojsimon Active Member

    Messages:
    459
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    basically what i want is to for a user to be able to enter a site and then highight the area they want and the script to return the html, is this possible? and if so how?

    Thanks
     
    ojsimon, Dec 20, 2007 IP
  4. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #4
    Use this function I have came up with, it is good because it doesn't require regular expression.

    
    <?php
    // USAGE
    $str = "<b>Bold Text 1</b><b>Bold Text 2</b>";
    $boldedText = between("<b>", "</b>", $str);
    print_r($boldedText);
    
    // FUNCTION
    function between($start, $end, $source) {
        while ($s != strlen($start)) {
            $s = strpos($source, $start, $s) + strlen($start);
            if ($s == strlen($start)) continue;
            $r[] = substr($source, $s, strpos($source, $end, $s) - $s);
        }
        return (count($r) <= 1 ? $r[0] : $r);
    }
    ?>
    
    PHP:
     
    Kaizoku, Dec 20, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    What's good about that?


    And ojsimon, that might be possible, but it would be very complicated. And you'd need JavaScript or Flash as well. No one here is going to code it just because...

    Perhaps you want to try your luck in the Buy sell trade section.
     
    nico_swd, Dec 21, 2007 IP
  6. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #6
    Because regex is slower than strpos and substr
     
    Kaizoku, Dec 21, 2007 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    Your script has a lot of function calls (also inside loops, which is expensive). I wouldn't be too sure about the speed in this case. With RegEx, you can do the job with one single function call, while yours has quite a lot.
     
    nico_swd, Dec 22, 2007 IP