I have a table with a field that contains descriptions for items sold on my site.
In our infinite wisdom, when we first started the site, we pasted code for a Facebook Like button into the description, each just a little different, as it has product info in the link. We now have about 400 items with the code in it.
This is an example of what I'm dealing with:
-Whipped Up, Fluffy Chocolate-On-Chocolate Taste; A Lighter Way To Enjoy Chocolate
- 45% Less Fat
< iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.oursite.com%2Findex.php%3Fmain_page%3Dproduct_info%26cPath%3D33_36%26products_id%3D106&layout=standard&show_faces=true&width=450&action=like&colorscheme=light&height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true">< /iframe>
I want to remove the <iframe
and everything past it. I have been looking around for examples using REPLACE and/or LEFT, but can't find what I need, as I am not very well versed in SQL language.
It will always be at the end of the products_description field, so I don't need to worry about saving anything past it, only before it.
The best I can come up with is
SELECT LEFT(REPLACE('<iframe%','<iframe%',' '),0)
but that doesn't seem to work.
Thank you for any help you can offer on this, as it will take me much less time than editing each description.
UPDATE: Still haven't found an answer, after trying many variations of what has been suggested. It runs, but makes no edit to the column.
I also tried this, after finding it on another site. The same, but thought it might give someone an idea of how to proceed:
select left(`products_description`,instr('<iframe',`products_description`)-1) FROM products_description
For better understanding i did not removed space between
<
andiframe
.You may also take a look at this thread:
Remove HTML tags from record
but this is discussion about removing tags only, and keeping
<tag>
text</tag>
between tags. Anyway it will for for you, because you have nothing between<iframe>
and</iframe>
.REPLACE('<iframe%','<iframe%',' ')
will give you just ' ' - it searches first argument for second argument and replaces it with third.LEFT(somestring, 0)
will give you 0 characters stringTry this: