I have a custom scripted forum and need to automatically add an alt tag to all images. The alt tag should be the same as forum title. This is what code in my commons.php that handles BBCode for images looks like: $patterns[] = "#\[img\]([^?](?:[^\[]+|\[(?!url))*?)\[/img\]#i"; $replacements[] = '<img src="\\1" border="0">'; Code (markup): I need to add alt="$topicname" to it. How do I do that? Obviously, if I added this exact text string to the code, each image will have a static alt tag which will be this text string - $topicname. Can anyone help a newb out? How do I make this alt tag dynamic, so it shows the actual value of $topicname. Thank you
You have to concatenate the variable $topicname into the replacement. $replacements[] = '<img src="\\1" border="0" alt='" . $topicname . "'>'; Something like that.. I always for get how PHP concatenation works.
Doesn't seem to work. This is what I get with the following: alt="' . $topicname . '" --> alt="" alt=" . $topicname . " --> alt=" . $topicname . "
Is the variable set? alt="' . $topicname . '" --> alt="" PHP: It looks like PHP evaluated the variable.. but it was empty so it returned a null value.
this is what I tried but it returns empty value. Obviously I'm missing something. I'm too much of a beginner to know what
Towards the top of the script add: $topicname = 'Test String'; Code (markup): After that the alt tag of all the images should be "Test String." If it is that means the variable isn't being set by the script. If it isn't that means there is something wrong with the concatenation of the replacement array.
Good catch, no, it's not. I've been using that variable in another file and it worked there. What do I need to do?
Are you sure you aren't using something like phpBB? I noticed you said you edited commons.php.. there is also a commons.php found in PHPBB3 If it's custom you should be able to just ask the coder to define the $topicname variable in commons.php
You're absolutely right. I think I'm messing with something that's above my capabilities and probably should leave it, cause I don't know where to pull the dynamic content I need from. The alt tag is supposed to display the title of the thread, which it $topicname - as it works whenused in other files. Obviously my common.php file misses something that's why it's not working for me. After adding the code above, my images display an alt="Test String" tag
It's a custom script and I could ask a coder who created it, but I thought I was gonna try to learn something on my own, but I'm failing miserably
Yes, I would just contact the coder. It's not wise to start randomly including other files without knowing what they specifically do. (security/performance issues) Good luck
Thanks a lot guys, I'm gonna leave it as I'm not up to par with the task I thought I was gonna do. You've been both helpful and green rep is on the way for the both of you. Keep rocking. BTW - Hermione didn't die.... Not yet