Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Stripping out characters

Participant ,
Jan 09, 2009 Jan 09, 2009
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.
581
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 10, 2009 Jan 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 els...
Translate
Explorer ,
Jan 09, 2009 Jan 09, 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>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 09, 2009 Jan 09, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 09, 2009 Jan 09, 2009
Anyone?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 10, 2009 Jan 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>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 10, 2009 Jan 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 20, 2009 Feb 20, 2009
LATEST
I read and understand. However, is there a source you recommend for regex tutes?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 12, 2009 Jan 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>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources