I'm storing an HTML values in my database then I output it on my site.
There was an HTML value that has a "cut off" HTML (I don't have control on the HTML, since I'm getting it on a different website" ), meaning to say, it looks like this
<a href="http://site.com
When I output this on my site I'm having a problem because below those "cut off" HTML, other HTML will be affected, so it looks like this (example)
<a href="http://site.com <input type="button" value="test" />
My question here is that how would I know if an HTML is being cut off, then if it has been cut off, I want to close it by simple closing it with " or />
A way to see if it's cut off or not would be to look if the amount of <'s is the same as the amount of >'s. So like this:
<?php
list($len, $a, $b) = array(strlen($html), 0, 0);
for ($i = 0; $i < $len; $char = $html[$i++]) {
if ($char == '<')
$a++;
if ($char == '>')
$b++;
}
$broken = true;
if ($a == $b)
$broken = false;
How do you store them in the database? Are they cut off in database too? If yes, then make sure you store them in database through mysql_real_escape_string(), since it seems your HTML gets broken due to being inserted into database somehow.