Xenalin
Xenalin

Reputation: 223

How to add alt text to an image inserted from PHP

I have an html file with this line:

<div >%%GLOBAL_ProductThumb%%</div>

and live it generates this:

<img width="200px" height="200px" alt="" src="[I removed the URL]">

In a PHP file, I see the variable being assigned on this line

$GLOBALS['ProductThumb'] = ImageThumb200x200($rowimg['imagefile']);

I don't know much about PHP, but how can I add fill the "alt" property with text? In what step/where would this occur? If this were Java I wouldn't have a problem figuring out how to set the property of an object, but I'm not quite sure what's going on here. If the context helps, it's custom shopping cart software designed for our business.

Upvotes: 0

Views: 1184

Answers (2)

Julian
Julian

Reputation: 757

PHP has no standard means to add some HTML attribute to a HTML tag. All you can do is build the HTML code as a string, then printing out the string. Which is something your software does by grabbing some other variables, giving you little direct influence on the generated code.

That said, the only thing you can do is inspecting what exactly all those custom functions are returning. If you are lucky, you find the exact HTML code that will land on the page in the end somewhere. From there, it's just a matter of programmatically searching and replacing before handing the final string further down the line.

Upvotes: 2

Paullo
Paullo

Reputation: 2127

A jquery hack can do that for you. If you can penetrate that third party app. You can embed a Jquery code that can take care of it on DOM Ready event. Example:

<script type="text/javascript">
    $(document).ready(function(){
        $("img[width='200px'][height='200px']").prop("alt", "Your ALT value");
    })
</script>

Upvotes: 0

Related Questions