Earendil
20th September 2009, 02:44 AM
EDIT: I fixed the problem by wrapping the title and alt text in single quotes.
In my database, I have an image table with ID, SRC, TITLE, and ALT columns. My problem is with this line of code I have on the site to display the images.
echo " <img src=\"".$row['src']."\" title=".$row['title']." alt=".$row['alt']." /> ";
The image displays fine, but the title and alt text are both cut off at the first white space. So if the alt text is "Bob rocks" the alt just shows "Bob". I've already echo'ed $row['title'] and it's being retrieved as the full string from the database. I've even tried replacing spaces with  , but that gets included literally. Even randomly tried htmlspecialchars and htmlentities, but those obviously didn't help.
Oh, and I've tried just putting in something like title="static text" instead of with a variable, and that works fine.
So, there's obviously something wrong with... something. My DB collation is utf8_unicode_ci if that makes a difference.
PS: On an unrelated note, I just noticed my use of the <img> tag in my title adversely affected the new post sidebar thing. Whoever runs that might want to fix that...or not.
In my database, I have an image table with ID, SRC, TITLE, and ALT columns. My problem is with this line of code I have on the site to display the images.
echo " <img src=\"".$row['src']."\" title=".$row['title']." alt=".$row['alt']." /> ";
The image displays fine, but the title and alt text are both cut off at the first white space. So if the alt text is "Bob rocks" the alt just shows "Bob". I've already echo'ed $row['title'] and it's being retrieved as the full string from the database. I've even tried replacing spaces with  , but that gets included literally. Even randomly tried htmlspecialchars and htmlentities, but those obviously didn't help.
Oh, and I've tried just putting in something like title="static text" instead of with a variable, and that works fine.
So, there's obviously something wrong with... something. My DB collation is utf8_unicode_ci if that makes a difference.
PS: On an unrelated note, I just noticed my use of the <img> tag in my title adversely affected the new post sidebar thing. Whoever runs that might want to fix that...or not.