Skip to main content
Inspiring
April 18, 2006
Question

"InnerHTML" in PHP?

  • April 18, 2006
  • 27 replies
  • 2656 views
How would I use PHP to copy the filename into the alt attribute? For
example,

<img
src="a-really-long-filename-that-I-also-want-to-use-without-hyphens.jpg"
alt="<?php echo("WHATTHEHECKGOESHERE?"); ?>">

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================



This topic has been closed for replies.

27 replies

Inspiring
April 18, 2006
"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:e23kjr$adb$1@forums.macromedia.com...
> Thanks bud! What I really need, though, is something that will do this
> when the page loads, not inside of DW. And I need it to strip the dashes
> when it does.

I see! try this out:

<script type="text/javascript">
function loadAlt(){
var imgNodes = document.getElementsByTagName("img");
for(var i=0; i<imgNodes.length; i++){
var cleanedSrc = imgNodes .src.replace("-", "");
imgNodes
.setAttribute("alt", cleanedSrc);
}
}
</script>
</head>
<body onload="loadAlt()">

Hope it will help, it's late here and I am ready to go to bed :-)

Massimo


Inspiring
April 18, 2006
Massimo:

Thanks bud! What I really need, though, is something that will do this when
the page loads, not inside of DW. And I need it to strip the dashes when it
does.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Massimo Foti" <massimo@massimocorner.com> wrote in message
news:e23kbr$a0h$1@forums.macromedia.com...
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:e23j2o$8fb$1@forums.macromedia.com...
>> Hmm - I think I will have to do it with javascript. I have a page with a
>> bunch of images on it. I want to snoop out each src attribute's value,
>> strip the dashes out, and place the resulting string into the alt
>> attribute.
>
> I attached a DW's query you can use. It doesn't strip the dashes out, but
> adds an alt attribute, with its value being equal to the src attribute.
> It's a quick and dirty solution, so please be careful, backup first and
> test it. Keep in mind it assumes the alt attribute is totally missing.
>
> Hope it could help
>
> BTW I hope other forum users don't mind the attachment...
>
>
> --
> ----------------------------
> Massimo Foti
> Tools for ColdFusion and Dreamweaver developers:
> http://www.massimocorner.com
> ----------------------------
>
>
>


Inspiring
April 18, 2006
> If it's a static page, then you'd HAVE to use javascript...as PHP only
> executes server-side.

I was first thinking that I could use the PHP to determine the value of the
src attribute for that particular image. But I realized on reflection that
that would come from the DOM.

> Again, though, a filename isn't terribly useful in the alt attribute in
> most cases.

I have my reasons! 8)

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"darrel" <notreal@nowhere.com> wrote in message
news:e23jap$8pg$1@forums.macromedia.com...
>
>> It's a static page!
>>
>> Hmm - I think I will have to do it with javascript.
>
> If it's a static page, then you'd HAVE to use javascript...as PHP only
> executes server-side.
>
>> I have a page with a bunch of images on it. I want to snoop out each src
>> attribute's value, strip the dashes out, and place the resulting string
>> into the alt attribute.
>
> Yes, javascript would work.
>
> I imagine the logic would be to:
>
> - find all IMG objects on page and set to an array.
> - loop through the array grabbing each img's SRC
> - parse the string
> - replace value of alt with new string
>
> Alas, you'll have to wait for one of the javascript experts to actually
> show you how to do that ;o)
>
> Again, though, a filename isn't terribly useful in the alt attribute in
> most cases.
>
> -Darrel
>


Inspiring
April 18, 2006
"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:e23j2o$8fb$1@forums.macromedia.com...
> Hmm - I think I will have to do it with javascript. I have a page with a
> bunch of images on it. I want to snoop out each src attribute's value,
> strip the dashes out, and place the resulting string into the alt
> attribute.

I attached a DW's query you can use. It doesn't strip the dashes out, but
adds an alt attribute, with its value being equal to the src attribute. It's
a quick and dirty solution, so please be careful, backup first and test it.
Keep in mind it assumes the alt attribute is totally missing.

Hope it could help

BTW I hope other forum users don't mind the attachment...


--
----------------------------
Massimo Foti
Tools for ColdFusion and Dreamweaver developers:
http://www.massimocorner.com
----------------------------


begin 666 murray.dwr
M/#]X;6P@=F5R<VEO;CTB,2XP(C\^#0H\9'=Q=65R>3X-"B @/'%U97)Y<&%R
M86US(&UA=&-H8V%S93TB=')U92(@:6=N;W)E=VAI=&5S<&%C93TB9F%L<V4B
M('5S97)E9V5X<#TB=')U92)W:&]L97=O<F0](F9A;'-E(B\^#0H@(#QF:6YD
M/@T*(" @(#QQ=&5X="!Q;F%M93TB*"9L=#MI;6=;7B9G=#M=*BES<F,])G%U
M;W0[*"XJ*29Q=6]T.RA;7B9G=#M=*B9G=#LI(B!Q<F%W/2)T<G5E(CX\+W%T
M97AT/@T*(" \+V9I;F0^#0H@(#QR97!L86-E(&%C=&EO;CTB<F5P;&%C951E
M>'0B('!A<F%M,3TB)#%S<F,])G%U;W0[)#(F<75O=#L@86QT/29Q=6]T.R0R
D)G%U;W0[("0S(B!P87)A;3(](B(O/@T*/"]D=W%U97)Y/@T*
`
end

Inspiring
April 18, 2006

> It's a static page!
>
> Hmm - I think I will have to do it with javascript.

If it's a static page, then you'd HAVE to use javascript...as PHP only
executes server-side.

> I have a page with a bunch of images on it. I want to snoop out each src
> attribute's value, strip the dashes out, and place the resulting string
> into the alt attribute.

Yes, javascript would work.

I imagine the logic would be to:

- find all IMG objects on page and set to an array.
- loop through the array grabbing each img's SRC
- parse the string
- replace value of alt with new string

Alas, you'll have to wait for one of the javascript experts to actually show
you how to do that ;o)

Again, though, a filename isn't terribly useful in the alt attribute in most
cases.

-Darrel


Inspiring
April 18, 2006
It's a static page!

Hmm - I think I will have to do it with javascript. I have a page with a
bunch of images on it. I want to snoop out each src attribute's value,
strip the dashes out, and place the resulting string into the alt attribute.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"darrel" <notreal@nowhere.com> wrote in message
news:e23d0d$11p$1@forums.macromedia.com...
>> How would I use PHP to copy the filename into the alt attribute? For
>> example,
>>
>> <img
>> src="a-really-long-filename-that-I-also-want-to-use-without-hyphens.jpg"
>> alt="<?php echo("WHATTHEHECKGOESHERE?"); ?>">
>
> Why would you want the filename in the alt attribute?
>
> If you did, though, PHP being server side, you'd just serve the SRC and
> ALT attribute the same string variable.
>
> -Darrel
>


Inspiring
April 18, 2006
> How would I use PHP to copy the filename into the alt attribute? For
> example,
>
> <img
> src="a-really-long-filename-that-I-also-want-to-use-without-hyphens.jpg"
> alt="<?php echo("WHATTHEHECKGOESHERE?"); ?>">

Why would you want the filename in the alt attribute?

If you did, though, PHP being server side, you'd just serve the SRC and ALT
attribute the same string variable.

-Darrel


Participating Frequently
April 18, 2006
echo '<img src="' . $filename . '" alt="' . $filename . '"/>';