regex help

Discussion in 'PHP' started by jiggyjiggy, Apr 9, 2008.

  1. #1
    Does anyone know a good regex that will make these two changes to the same url?

    a) add a folder name to the url
    b) add .html at the end of the url

    I will prefer to do this on the html code rather than on the fly. So from:

    <a href="http://mydomain.com/url1">
    <a href="http://mydomain.com/url2">
    etc..

    To

    <a href="http://mydomain.com/folder/url1.html">
    <a href="http://mydomain.com/folder/url2.html">
    etc..

    Many thanks.
     
    jiggyjiggy, Apr 9, 2008 IP
  2. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #2
    I would go for something simple and do:

    str_replace('http://sitename.com/','http://sitename.com/folder/',$text);

    if you parse it once itll work fine

    else you will want to use "folder/" as the stop condition in your ereg_replace
     
    m0nkeymafia, Apr 9, 2008 IP