SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Jan 2005
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    replace esiting data?

    What i need to do is take some existing data and replce it in mysql with new data. Basicly take html tags out of a field and in the case of <BR> replace that with \n

    the only thing is i don't know how to do this with a single query to the database. I know i can use PHP and put it in a loop but i thought it would be better to just run a single sql statement to do the job for me.

    is it possable? i found REPLACE in the mysql manual is that something i need to use? it don't look like it to me though. If somebody could help me out with this it would be great!

    thanks

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    if you have html tags in the data stored in mysql, it will not be possible to strip them all out easily

    you could use multiple iterations of the REPLACE function, but this will only replace exact matching strings

    e.g. you can say REPLACE(htmlcolumn,'<p>','') but that will not handle tags like <p id="foo">

    unfortunately, mysql's REGEXP only matches, it doesn't replace
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2005
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey rudy thanks for the reply, I ended up writing a php script to do it for me. Just threw in a while loop and parse 150,000 records and everything went fine.

    Thanks for the reply!


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
  •