WTB: Solve this Simple PHP Regex for $5, Or Provide efficient alternate solution

Discussion in 'Programming' started by jawahar, Oct 14, 2008.

  1. #1
    Hi..
    Please solve the below regex problem and will pay $5 through paypal!!

    $data="asd<br>asd asd<b>anti spyware for mac</b> asd asdas free mac spyware das d<b>ret from mac spyware remover to mac home</b>";
    $srch="free mac spyware";
    $regex = "/.*<b[^>]*?>(.*?.'.$srch.'.*?)<\/b>/i";
    preg_match($regex,$data,$matches);

    It is not matching properly and it outputs,
    <b>anti spyware for mac</b> asd asdas free mac spyware das d<b>ret from mac spyware remover to mac home</b>";

    Required Output is:
    Nothing!!! Null because it is not present in <b></b> tags

    If the $srch="mac spyware remover"; Then Required Output is:
    ret from mac spyware remover to mac home

    Or, if you are able to provide another EFFICIENT solution as a reusable function to perform the task, it is also appreciable

    Regards
    Jawahar
     
    jawahar, Oct 14, 2008 IP
  2. Depix

    Depix Peon

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    I'll do it. PMed you.
     
    Depix, Oct 14, 2008 IP
  3. jawahar

    jawahar Active Member

    Messages:
    1,044
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    the first one to provide the working solution gets it !!!
     
    jawahar, Oct 14, 2008 IP
  4. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    i don't understand what u want. (?.?)
     
    ads2help, Oct 14, 2008 IP
  5. jawahar

    jawahar Active Member

    Messages:
    1,044
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #5
    basically i want to find if a specific word appears in BOLD TAG or not. Similarly for Anchor TAG also!!`
     
    jawahar, Oct 14, 2008 IP
  6. qprojects

    qprojects Peon

    Messages:
    1,901
    Likes Received:
    103
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #6
    <?php
    $data="asd<br>asd asd<b>anti spyware for mac</b> asd asdas free mac spyware das d<b>ret from mac spyware remover to mac home</b>";
    $srch="mac spyware remover";
    $regex = "/<b\s*?>([^<]*?" . $srch . ".*?)<\/b>/";
    preg_match($regex,$data,$m);
    echo '<pre>';
    print_r($m);
    ?>
    PHP:
     
    qprojects, Oct 14, 2008 IP
  7. jawahar

    jawahar Active Member

    Messages:
    1,044
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #7
    qprojects: If there are any other tags inside <b> it will not match :-(


    No Problem !! Thanks guys.. I have solved this by doing a preg_match_all and getting all B tags and then matching with a for loop !!


    THREAD CLOSED !
     
    jawahar, Oct 14, 2008 IP