Replace links with regex

Discussion in 'PHP' started by sastro, Sep 17, 2008.

  1. #1
    In the text file, there's some links like this <a href="http://www.domain.com/link1.html">, <a href="/link1.html">, <a href="link2.html">.
    How to replace all links to <a href="http://www.domain.com/link1.html">, <a href="http://www.domain.com/link2.html">, <a href="http://www.domain.com/link3.html"> using regex ?

    Thx
     
    sastro, Sep 17, 2008 IP
  2. chessh

    chessh Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What do you exactly intend to do?
     
    chessh, Sep 17, 2008 IP
  3. sastro

    sastro Well-Known Member

    Messages:
    214
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    How to preg_replace link like this :
    <a href="http://www.domain.com/link1.html">
    <a href="/link1.html">
    <a href="link2.html">

    to
    <a href="http://www.domain.com/link1.html">
    <a href="http://www.domain.com/link2.html">
    <a href="http://www.domain.com/link3.html">
    from a string parsed from a webpage.
     
    sastro, Sep 17, 2008 IP