SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question PHP regular expression help

    Hi,

    I need to replace the anchor tag with text

    Example:
    <a href=aaa.php>aaa</a> should be replaced as ccc

    any help is appreciated.

  2. #2
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why ccc? From where is "ccc"??? you can use str_replace for your problem, like this str_replace('<a href="aaa.php">aaa</a>', 'ccc', $yourHTMLString);

  3. #3
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ccc is just an example.
    all anchor tags should be replaced by a text.
    The anchor tags have different href values.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    PHP Code:
    preg_replace('/<a[^>]*>.*?<\/a>/''ccc''Let us see if <a href="whatever">whatever</a> this regex gets all the <a>anchor tags</a> ?'); 
    result:
    Code:
    "Let's see if ccc this regex gets all the ccc ?"
    I used this tutorial to put the regex together, and this regex tester to test it (there are lots of them, I found this one googling for 'preg_replace tester').

  5. #5
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This code works...Thank you...


Tags for this Thread

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
  •