Forum Moderators: open

Message Too Old, No Replies

Validating XHTML1.0 problem

         

sicsiksix

6:56 pm on Mar 22, 2010 (gmt 0)

10+ Year Member



Aplogies if this is in the wrong section, it's my first post!

I'm currently getting the following error when validating my page (and 2 similar pages) as XHTML 1.0 Transitional:
character "&" is the first character of a delimiter but occurred as data

I have been through all the pages and fixed all & to appear as & in the code, but the remaining ones are taken from a database.

My code is as follows:
while ($row = mysql_fetch_array($result)) {

$title=$row['title'];
$imdb=$row['imdb'];

echo "<tr class=\"d".($j & 1)." $style\">";
echo "<td><a href=\"$imdb\" title=\"$title\" target=\"_blank\">$title</a></td>";
echo "</tr>";
$j++;
}


The page displays correctly, but any & contained in the title in the database doesn't get changed to &amp; when it is called.

What confuses me though is that the ones within the title="" part do get validated. Is there a way to force & to be changed to &amp; when called from a database?

Also the same problem occurs when I enter &amp; into the database itself.

Thanks.

dreamcatcher

7:42 am on Mar 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A warm welcome to WebmasterWorld sicsiksix. :)

Use str_replace [php.net]:

$title = str_replace('&','&amp;',$title);
echo "<td><a href=\"$imdb\" title=\"$title\" target=\"_blank\">$title</a></td>";

You probably should have posted this in PHP.

dc

sicsiksix

2:03 pm on Mar 23, 2010 (gmt 0)

10+ Year Member



Thanks a lot, that did the trick!

Apologies for completely missing the PHP section, will check more closely in future! :)

dreamcatcher

7:50 pm on Mar 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No problem. Glad it worked ok. :)