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 19, 2006
> I am using an app that can display the alt attribute's value as a photo
> caption.

Ewww...

Any chance you can modify the app to use the TITLE attribute?

> What's that you say? Why don't I use a database? That would, of course,
> be the obvious solution. But his data is not in a form that lends itself
> to that approach at this moment! 8(

If you can hold off for a few weeks, I might have a solution for you...(I'm
working on a database driven photo gallery application)

Otherwise, maybe look at Gallery or some other system that your brother
could upload the images to himself (thereby taking you out of the loop ;o)

-Darrel


Inspiring
April 19, 2006
> Wouldn't that lead to captions like
> "areallylongfilenamethatIalsowanttousewithouthyphens"? What's the
> purpose of that?

When I said 'strip hyphens' what I really meant was 'replace them with
spaces'. 8)

> Everything like this should be done on the server.

Yes - which explains why I have this thread under the subject I chose. But
I can't think of a good way to do it server-side.

> I would still probably go the DB-route and use the filename as a first,
> initial caption. It allows to easily modify the captions to a more
> reasonable and more descriptive text at a later time.

Yes. Of course that's the best method....

--
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
==================


"Michael Fesser" <netizen@gmx.de> wrote in message
news:n86c4297t1goi9jh5ig6dleurqvk3hm1lk@4ax.com...
> .oO(Murray *ACE*)
>
>>I am using an app that can display the alt attribute's value as a photo
>>caption. This would be why I am asking these goofy questions - to
>>automatically transfer the filename to the alt attribute, and to strip out
>>the hyphens.
>
> Wouldn't that lead to captions like
> "areallylongfilenamethatIalsowanttousewithouthyphens"? What's the
> purpose of that?
>
>> But I think a stake has been driven through this one's heart
>>by the comment that dynamically written content like that is not 'on the
>>page'. So - I'm back to the drawing board.
>
> Everything like this should be done on the server.
>
>>What's that you say? Why don't I use a database?
>
> Would be helpful for storing the captions and maybe additional
> informations about each picture (keywords, date etc.)
>
>>That would, of course, be
>>the obvious solution. But his data is not in a form that lends itself to
>>that approach at this moment! 8(
>
> I would still probably go the DB-route and use the filename as a first,
> initial caption. It allows to easily modify the captions to a more
> reasonable and more descriptive text at a later time.
>
> Micha


Inspiring
April 19, 2006
Really? On a joke site? 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
==================


"Michael Fesser" <netizen@gmx.de> wrote in message
news:7b5c429idus3oeaoga6qv3mbrl6nick3g4@4ax.com...
> .oO(Murray *ACE*)
>
>>That's in all my pages now! 8)
>
> I've already seen such code "in the wild" ...
>
> Micha


Inspiring
April 19, 2006
.oO(Murray *ACE*)

>I am using an app that can display the alt attribute's value as a photo
>caption. This would be why I am asking these goofy questions - to
>automatically transfer the filename to the alt attribute, and to strip out
>the hyphens.

Wouldn't that lead to captions like
"areallylongfilenamethatIalsowanttousewithouthyphens"? What's the
purpose of that?

> But I think a stake has been driven through this one's heart
>by the comment that dynamically written content like that is not 'on the
>page'. So - I'm back to the drawing board.

Everything like this should be done on the server.

>What's that you say? Why don't I use a database?

Would be helpful for storing the captions and maybe additional
informations about each picture (keywords, date etc.)

>That would, of course, be
>the obvious solution. But his data is not in a form that lends itself to
>that approach at this moment! 8(

I would still probably go the DB-route and use the filename as a first,
initial caption. It allows to easily modify the captions to a more
reasonable and more descriptive text at a later time.

Micha
Inspiring
April 19, 2006
Thanks, Massimo.

Here's the deal: I'm making a photo gallery for my brother. He has
hundreds, nay thousands, of images taken all over the world (as a
professional wildlife photographer). He gives me the images with names as I
indicated earlier (words and keywords separated by hyphens).

I am using an app that can display the alt attribute's value as a photo
caption. This would be why I am asking these goofy questions - to
automatically transfer the filename to the alt attribute, and to strip out
the hyphens. But I think a stake has been driven through this one's heart
by the comment that dynamically written content like that is not 'on the
page'. So - I'm back to the drawing board.

What's that you say? Why don't I use a database? That would, of course, be
the obvious solution. But his data is not in a form that lends itself to
that approach at this moment! 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
==================


"Massimo Foti" <massimo@massimocorner.com> wrote in message
news:e23lb2$b7r$1@forums.macromedia.com...
> "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 19, 2006
.oO(Murray *ACE*)

>That's in all my pages now! 8)

I've already seen such code "in the wild" ...

Micha
Inspiring
April 19, 2006
That's in all my pages now! 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
==================


"Michael Fesser" <netizen@gmx.de> wrote in message
news:noub42h6og0uqo3bkv6hcs858rece9vlrj@4ax.com...
> .oO(Massimo Foti)
>
>>"David Powers" <david@example.com> wrote in message
>>news:e23n2q$dc7$1@forums.macromedia.com...
>>
>>> It also relies on JavaScript being enabled.
>>
>>That's the nature of JavaScript :-)
>
> alert('Please enable JavaScript to view this site!');
>
> Micha


Inspiring
April 19, 2006
.oO(Massimo Foti)

>"David Powers" <david@example.com> wrote in message
>news:e23n2q$dc7$1@forums.macromedia.com...
>
>> It also relies on JavaScript being enabled.
>
>That's the nature of JavaScript :-)

alert('Please enable JavaScript to view this site!');

Micha
Inspiring
April 19, 2006
"David Powers" <david@example.com> wrote in message
news:e23n2q$dc7$1@forums.macromedia.com...
> That would definitely do what Murray wants, but it would apply to all
> images on a page.

Muray wrote: "I want to snoop out each src attribute's value"



> It also relies on JavaScript being enabled.

That's the nature of JavaScript :-)



> So, to remain valid, you would need to set a default alt attribute.

I usually don't care about valdity, but sounds like a good suggestion


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


Inspiring
April 18, 2006
Massimo Foti wrote:
> 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()">

That would definitely do what Murray wants, but it would apply to all
images on a page. It also relies on JavaScript being enabled. So, to
remain valid, you would need to set a default alt attribute.

I suspect that Murray probably needs something that works using
getElementById, rather than getElementsByTagName. Alternatively, you
might need getElementsByTagName combined with getAttribute('class') to
whip through those images that are set to a particular class.

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/