Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11

Thread: Regex

  1. #1
    HG3
    HG3 is offline
    New Coder
    Join Date
    Sep 2011
    Location
    BRAZIL
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Regex

    please how to get XXX in text

    PHP Code:
    $content = @file_get_contents("http://mysite.com/test.html");
    if (
    $content !== false){

    // GET XXX
    $pattern "/<script>setTimeout("test(XXX,' http://www.mysite.com')",66000);</script>/i";

    preg_match_all($pattern$content$matches);
    echo 
    var_dump($matches);
    }else{
    echo 
    'ERRO';


  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by HG3 View Post
    please how to get XXX in text

    PHP Code:
    $content = @file_get_contents("http://mysite.com/test.html");
    if (
    $content !== false){

    // GET XXX
    $pattern "/<script>setTimeout("test(XXX,' http://www.mysite.com')",66000);</script>/i";

    preg_match_all($pattern$content$matches);
    echo 
    var_dump($matches);
    }else{
    echo 
    'ERRO';

    And what have you tried so far?
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #3
    HG3
    HG3 is offline
    New Coder
    Join Date
    Sep 2011
    Location
    BRAZIL
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts
    already tried that

    PHP Code:

    $content 
    = @file_get_contents("http://mysite.com/test.html");
    if (
    $content !== false){
    $pattern '/<script>setTimeout(\"teste(\(.*?),http:\/\/mysite.com\/test.html/)",66000/);<\/script>/i';
    preg_match_all($pattern$content$matches);
    echo 
    var_dump($matches);

    }else{
    echo 
    'ERRO';

    Last edited by HG3; 01-17-2012 at 08:39 AM.

  • #4
    HG3
    HG3 is offline
    New Coder
    Join Date
    Sep 2011
    Location
    BRAZIL
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts
    ? :-(

  • #5
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by HG3 View Post
    already tried that

    PHP Code:

    $content 
    = @file_get_contents("http://mysite.com/test.html");
    if (
    $content !== false){
    $pattern '/<script>setTimeout(\"teste(\(.*?),http:\/\/mysite.com\/test.html/)",66000/);<\/script>/i';
    preg_match_all($pattern$content$matches);
    echo 
    var_dump($matches);

    }else{
    echo 
    'ERRO';

    Shouldn't it be test, not teste? Are you getting any error messages from preg_match_all (check error logs)? Also, should you have www. before mysite.com?

    It would make more sense to just match the setTimeout() if it's the only one that's gonna be on the page, surely? Kind of like this
    PHP Code:
    $return preg_match_all('/setTimeout\(\"test\((.*?)\,/',$content,$matches);
    if(
    $return 0){
        
    // matches found
        
    var_dump($matches);

    Last edited by BluePanther; 01-17-2012 at 02:37 PM.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    HG3 (01-17-2012)

  • #6
    HG3
    HG3 is offline
    New Coder
    Join Date
    Sep 2011
    Location
    BRAZIL
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php

    $content 
    = @file_get_contents("http://mysite.com/aaa.html"); 
    if (
    $content !== false){ 
    $pattern "/<script>setTimeout(\'test(\(.*?),' http:\/\/www.mysite.com\/test.html'/)',66000/);<\/script>/i"
    preg_match_all($pattern$content$matches); 
    echo 
    var_dump($matches); 

    }else{ 
    echo 
    'ERRO'
    }  

    ?>
    ERRO:

    Warning: preg_match_all() [function.preg-match-all]: Unknown modifier ')' in /home/mysite/public_html/test.php on line 6
    NULL
    Last edited by HG3; 01-17-2012 at 02:38 PM.

  • #7
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Edited my response above. You're not escaping the relevant parts of your regex, but you could be trying to match too much anyway. Try mine out
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    HG3 (01-17-2012)

  • #8
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    I omitted the i matching option, because it doesn't look like we really need it to be case insensitive - if you do need it, you should just tack the i back onto it.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    HG3 (01-17-2012)

  • #9
    HG3
    HG3 is offline
    New Coder
    Join Date
    Sep 2011
    Location
    BRAZIL
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts
    ok, thank you BluePanther.
    very thankful for help

  • #10
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by HG3 View Post
    ok, thank you BluePanther.
    very thankful for help
    Does it work like you want it to?
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    HG3 (01-17-2012)

  • #11
    HG3
    HG3 is offline
    New Coder
    Join Date
    Sep 2011
    Location
    BRAZIL
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by bluepanther View Post
    does it work like you want it to?
    yes =)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •