#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    113
    Rep Power
    10

    Regular expression


    PHP Code:
    $link_text 'Apply now';
                                    
    $content '<td align="right" class="apply">   <a href="http://domain.com?h=AJ&cm=Details_ApplyNow" onClick="ApplyNowClick(\'A7C6NP\');" title="Apply for this now!">Apply Now</a></td>';
                    

    $pattern '|<a[^>]+>('.$link_text.')</[^>]+>|U';   
    preg_match($pattern$content$output); 

                    
    $pattern '/<[a]{1}(.*)?>(.*)<\/[a]{1}>/';  
    $content trim(preg_replace($pattern'$1'$output[0])); 

    ... 
    // then parse $content to get the href url 

    Is it possible to know what is wrong with the regular expression to get the href of this tag?
    <td align="right" class="apply"> <a href="http://domain.com?h=AJ&cm=Details_ApplyNow" onClick="ApplyNowClick(\'A7C6NP\');" title="Apply for this now!">Apply Now</a></td>

    Not getting anything in $output. I've this code working for a similar <a ..> tag.

    Thanks!
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    Your match text has "now" but the link has "Now"
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    30
    Rep Power
    3
    regex patterns must start with '/' and ends with '/' , and after the last '/' add an 'i' to make case insenstive

    $pattern = '/regex/i'
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    Originally Posted by chris0
    regex patterns must start with '/' and ends with '/'
    Not necessarily.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    30
    Rep Power
    3
    Originally Posted by requinix
    Not necessarily.
    yes you are right, its however appears to be the standered and better for script consistency imo

    still though, the i modifier should make it case insensitive
  10. #6
  11. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    Originally Posted by chris0
    yes you are right, its however appears to be the standered and better for script consistency imo
    Unless of course the pattern contains a / (which this one did), which would force you to escape the / if it's in the pattern, leading to patterns that contain \/ everywhere, which are harder to read than if you had chosen a new delimiter.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2006
    Posts
    19
    Rep Power
    0
    This should do the trick.

    PHP Code:
    <?php

    $content 
    '<td align="right" class="apply">   <a href="http://domain.com?h=AJ&cm=Details_ApplyNow" onClick="ApplyNowClick(\'A7C6NP\');" title="Apply for this now!">Apply Now</a></td>';

    preg_match('#<a href="(.+)" onClick=".+" title=".+">Apply Now</a>#U'$content$output);
    var_dump($output);

    ?>

IMN logo majestic logo threadwatch logo seochat tools logo