#1
  1. No Profile Picture
    Self Proclaimed
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    249
    Rep Power
    12

    Regular Expression Desperation. I'll PayPal $10 to whoever get's it working properly.


    For someone who knows what their doing this shouldn't be too hard; unfortunately for me, this my first time using regular expressions, and I don't have the luxury, or patience to learn them right now.

    I'll send $10 USD to anyone who gets it working the way I want. (I'll be sending it through Pay Pal, so you may need to have a premier account, I'm not sure.)

    I have written out a detailed explanation of the problem, with examples of what I need it to do.

    Please test it using the url http://www.yahoo.com. It has 3 JavaScript code blocks separated by text, so this will be a good test page for multiple uses of JavaScript.

    The other page is http://www.brainhosting.com. They have one JavaScript code block at the top, so this will be a good test page for just one.

    The first person to post the working code is the winner. If it doesn't work, I'll move on until I get one that does work. (So please test it yourself before you post it)

    Disclaimer: You agree to not try and hold any property rights to the regular expression, and that it shall be 100% royalty free. (I've learnt the hard way to cover my butt)

    Please visit http://www.arcanenexus.com for a more detailed explination.

    Thanks to all who help, and congrats to the first to get it working.
  2. #2
  3. No Profile Picture
    Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    Boston Ma.
    Posts
    1,529
    Rep Power
    0
    Hi


    Try something like this....

    untested but it should work!

    PHP Code:
    <?

        
    function strip_html($str) {
            
    $tab get_html_translation_table(HTML_ENTITIES);
            
    $tab array_flip($tab);
            return 
    strtr($str$tab);
        }

        function 
    text_mode($str) {
            return 
    strip_html(preg_replace(array("'<(SCRIPT|STYLE)[^>]*?>.*?</(SCRIPT|STYLE)[^>]*?>'si""'(\\r|\\n)'""'<BR[^>]*?>'i""'<P[^>]*?>'i""'<\\/?\\w+[^>]*>'e"), array("""""\\r\\n""\\r\\n\\r\\n"""), $str));
        }

    $page file_get_contents('http://www.yahoo.com/');
    $page text_mode($page);


    echo 
    $page;


    ?>



    F!
  4. #3
  5. No Profile Picture
    Self Proclaimed
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    249
    Rep Power
    12
    It poduced an error
  6. #4
  7. Prom night: 1973
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Dec 2001
    Posts
    1,156
    Rep Power
    24
    preg_replace needs to be set to ignore newlines. The '/s' modifier does it.

    Code:
    <?php
    
    $domain = 'http://www.yahoo.com/';
    
    $open = fopen($domain, "r");
    
    $readone = fread($open, 200000);
    $readtwo = stristr($readone, '<body');
    $readthree = preg_replace( "/<script[^>]+>.*?<\/script>/is", "", $readtwo);  //<-- extra modifier here
    //$readthree = eregi_replace("<script(.*)<\/script>/u", "", $readtwo);
    
    $read = strip_tags($readthree);
    
    fclose($open);
    
    $filtered = eregi_replace(" a ", " ", $read);
    $$filtered = eregi_replace(" about ", " ", $filtered);
    $$filtered = eregi_replace(" after ", " ", $$filtered);
    $$filtered = str_replace('"', ' ', $$filtered);
    
    echo trim($$filtered);
    
    ?>
  8. #5
  9. No Profile Picture
    Self Proclaimed
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    249
    Rep Power
    12
    Thanks kurious, it did everything I needed it to do. I've tested it on 5 five sites and were formatted perfectly. (well, still a few bugs to work out, the source of the formatted pages have a LOT of white space)

    Send me your Pay Pal details. (sales@arcanenexus.com) and I'll send you all money as I said I would.

    Thanks again.
  10. #6
  11. Prom night: 1973
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Dec 2001
    Posts
    1,156
    Rep Power
    24
    >Send me your Pay Pal details.

    That's not necessary. It's the season of good will

    If you feel the need to pay, you can buy something for rycamor He's helped me out a lot and has an Amazon wishlist at http://www.amazon.com/gp/registry/re...d=HBFZZHYLLOGH
    Last edited by kurious; December 17th, 2003 at 05:40 PM.
  12. #7
  13. No Profile Picture
    Self Proclaimed
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    249
    Rep Power
    12
    Thanks,

    I'll browse around for a book for my friend.
  14. #8
  15. No Profile Picture
    Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    Boston Ma.
    Posts
    1,529
    Rep Power
    0
    Hi

    First off, WHAT ERROR DID IT GIVE YOU, you say it gave you a error, but you don't say what the error is! After trying my code on 3 servers I see no error, I think you full of bull!





    http://ms.ya-right.net/yahoo.php


    F!
  16. #9
  17. No Profile Picture
    Self Proclaimed
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    249
    Rep Power
    12
    Fatal error: Call to undefined function: file_get_contents() in c:\phpdev\www\test.php on line 28

    This line specifically

    $page = file_get_contents('http://www.yahoo.com/');

    Tested on a windows box

IMN logo majestic logo threadwatch logo seochat tools logo