SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    This regex
    Code:
    '/<a[^>]+>(Apply now)<\/a>/i'
    returns this
    Code:
    Array
    (
        [0] => <a href="http://domain.com?h=AJ&cm=Details_ApplyNow" onClick="ApplyNowClick(\'A7C6NP\');" title="Apply for this now!">Apply Now</a>
        [1] => Apply Now
    )
    Doesn't look very useful to me.
    What is it you want to achieve with this code?

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2011
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you need only the href, try the following pattern
    PHP Code:
    $pattern '#href="([^"]+)"#i'


Bookmarks

Posting Permissions

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