1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Stripping Links with PHP?

Discussion in 'PHP' started by smashedpumpkins, Mar 27, 2010.

  1. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #21
    @stOK

    Which suggestions have been crap?, all my 'suggestions' have worked perfectly, its up to the OP to use my 'suggestions' appropriatly, I suggest you reread the thread/OP's posts.
     
    danx10, Mar 30, 2010 IP
  2. stOK

    stOK Active Member

    Messages:
    114
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #22
    The last crap was
    
    $content = preg_replace('~<(a.*)href=(.*?)>(.*)</a>~i', '$3', $content);
    
    Code (markup):
    try it on the following string
    $content = '<a href="http://www.google.com/">google</a> and <a href="http://www.moogle.com/">moogle</a>';
    or
    $content = '<acronym>AAA</acronym> Whole Page of very useful info <a href="link">link</a>';
    ...and many many more issues....

    rtfm
     
    stOK, Mar 30, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #23
    The regex may not be effective, but what the OP asked for is for the link text to remain...

    From your post I can identify 1 flaw:

    $content = preg_replace('~<(a.*)href=(.*?)>(.*)</a>~i', '$3', $content);

    Which can interfer with other tags containing a. On that basis yes I'll admit you got me ;) - but don't call my suggestions crappy - that way you'll never progress - what would have been better is something constructive.
     
    danx10, Mar 30, 2010 IP
  4. smashedpumpkins

    smashedpumpkins Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #24
    Okay so I switched over to....
    $content = preg_replace('%</?a\b[^>]*>%i', '', $content);
    PHP:
    Will the $3 also work in this strip of code? Now what would I use to have it remove the non a href link http://www.google.com? (The forum makes this a link automatically) Thanks a ton. I really appreciate it.
     
    Last edited: Mar 30, 2010
    smashedpumpkins, Mar 30, 2010 IP
  5. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #25
    @ dan & stOK - You are actually both wrong with it. The (.*) means $3 will leave everything between the first <a tag and the final </a> tag. Either way, arguing about it really is of no benefit to anyone so I don't know why you are really

    @smashedpumpkins - Take a look at http://regexlib.com/ for some example regex's for stripping url's
     
    JAY6390, Mar 30, 2010 IP
    danx10 likes this.
  6. stOK

    stOK Active Member

    Messages:
    114
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #26
    2nd flaw is that (.*) is too greedy for the task.

    @jay where I'm wrong?
     
    stOK, Mar 30, 2010 IP