SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2008
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Search and Replace from Database

    Hello friends

    I am retrieving the data from the database. I want to search for <a href> link in the column and replace it with the new one.

    Suppose the column in the database has following values

    <a href="../../../../../faqfile/">Click here</a>

    than I want to replace it like

    <a href="http://www.mysite.com/upload/faqfile/">Click here</a>

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you mean something like this?
    PHP Code:
    $string 'test <a href="../../../../../faqfile/">Click here</a> test';
    $pattern '/<a.*>(.*?)<\/a>/';
    echo 
    preg_replace($pattern'<a href="http://www.mysite.com/upload/faqfile/">$1</a>'$string); 
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Addict X-Cart's Avatar
    Join Date
    May 2009
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could try the following query
    update <table-name> set <field> = replace(<field>, '../../../', 'http://www.domain.com/')

    as alternative you need to select the data via sql, process it in PHP and then insert vis sql.

    Also some useful information can be found here:
    http://dev.mysql.com/doc/refman/5.1-...nction_replace
    X-Cart - tens thousands live online shops worldwide
    Follow us on Twitter


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
  •