Skip to main content
January 9, 2009
Answered

Stripping out characters

  • January 9, 2009
  • 6 replies
  • 655 views
I have an <img string that I want to manipulate. Here is the string.

<img src=" http://site.com/1.jpg" width="177" height="240" alt="image" />

The first thing I want to do is strip out the <img src=" and that is common on all the paths I want to manipulate so I thought I could do a simple Replace(). Then I'd end up with http://site.com/1.jpg" width="177" height="240" alt="image" />

I need to strip everything else off that string after the "

I'm not sure how to do that... can anyone help me out?




By the way, BKBK and Ian... that logout code is logging me out on all machines except my laptop at home. I'm about 80% satisfied with it. I still want to know why it won't work from my laptop.
    This topic has been closed for replies.
    Correct answer Newsgroup_User
    On Fri, 9 Jan 2009 19:07:45 +0000 (UTC), idesdema wrote:

    > I have an <img string that I want to manipulate. Here is the string.
    >
    > <img src=" http://site.com/1.jpg" width="177" height="240" alt="image" />
    >
    > The first thing I want to do is strip out the <img src=" and that is common on
    > all the paths I want to manipulate so I thought I could do a simple Replace().
    > Then I'd end up with http://site.com/1.jpg" width="177" height="240"
    > alt="image" />
    >
    > I need to strip everything else off that string after the "
    >
    > I'm not sure how to do that... can anyone help me out?

    So you want to extract the src value from an <img/> tag? That was a very
    long-winded way of describing what you need ;-)

    Use a regex, and you can do it in one expression.

    Match this: <img.*?src="([^"]*?)"[^>]*?>
    Replace it with: \1

    Pls take the time to read the regex docs and understand the solution I've
    given you...

    --
    Adam

    6 replies

    January 12, 2009

    Here's another silly way to do it...

    <cfsavecontent variable="link">
    <img src=" http://site.com/1.jpg" width="177" height="240" alt="image" />
    </cfsavecontent>

    <cfset doc = XmlParse(link) />

    <cfset img = doc.img.XmlAttributes.src />

    <cfoutput>
    [#img#]
    </cfoutput>
    Newsgroup_UserCorrect answer
    Inspiring
    January 10, 2009
    On Fri, 9 Jan 2009 19:07:45 +0000 (UTC), idesdema wrote:

    > I have an <img string that I want to manipulate. Here is the string.
    >
    > <img src=" http://site.com/1.jpg" width="177" height="240" alt="image" />
    >
    > The first thing I want to do is strip out the <img src=" and that is common on
    > all the paths I want to manipulate so I thought I could do a simple Replace().
    > Then I'd end up with http://site.com/1.jpg" width="177" height="240"
    > alt="image" />
    >
    > I need to strip everything else off that string after the "
    >
    > I'm not sure how to do that... can anyone help me out?

    So you want to extract the src value from an <img/> tag? That was a very
    long-winded way of describing what you need ;-)

    Use a regex, and you can do it in one expression.

    Match this: <img.*?src="([^"]*?)"[^>]*?>
    Replace it with: \1

    Pls take the time to read the regex docs and understand the solution I've
    given you...

    --
    Adam
    February 20, 2009
    I read and understand. However, is there a source you recommend for regex tutes?
    January 10, 2009

    I would be reluctant to use this code
    but at least it should get you going...

    <cfsavecontent variable="link">
    <img src=" http://site.com/1.jpg" width="177" height="240" alt="image" />
    </cfsavecontent>

    <cfset img = ListFirst(ListRest(link, '"'), '"') />

    <cfoutput>
    #img#
    </cfoutput>
    January 10, 2009
    Anyone?
    January 9, 2009
    I will be repeating this function over many database entries. The entries are similar but not the same. For example, the width and height and alt values are usually different.
    Inspiring
    January 9, 2009
    Try This:

    <cfset var = '<img src=" http://site.com/1.jpg" width="177" height="240" alt="image" />'>

    <cfoutput>#ReReplace(ReReplace(var,'<img src=',''),' width="177" height="240" alt="image" />','')#</cfoutput>