Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do i get it so it deletes/ignores ro something the HTML people put 1

Status
Not open for further replies.

unborn

Programmer
Jun 26, 2002
362
US
in my input boxes... when i load it up in my thing it messes up my stuff if they put sme html in it.. like </table> will kill my whole project.. i tried fgetss and :/ no luck.. besides i dont know how to really use it :/.

my first php solo project:


<?
$links = file(&quot;links.txt&quot;);
$linkcount = count($links);

if ($linkcount==0) echo &quot;No links are Available!&quot;;
else
{
echo &quot;<table border=0 cellspacing=1 cellpadding=1>
<tr>
<td bgcolor=black><font size=1 face=tahoma color=white><center><b>#</b></center></td>
<td bgcolor=black><font size=1 face=tahoma color=white><b>Links</b></td>
<td bgcolor=black><font size=1 face=tahoma color=white><b> Description</b></td>
</tr>&quot;;
$clr = &quot;l&quot;;
for($i=0; $i<$linkcount; $i++)
{
$num = $i+1;
$line = explode(&quot;\t&quot;,$links[$i]);
if ($clr == &quot;l&quot;)
{
echo &quot;<tr>
<td bgcolor=eeeeee align=right><font color=black size=1 face=tahoma>$num.</td>
<td bgcolor=eeeeee><font color=black size=1 face=tahoma> <a href=$line[1] target=_new>$line[0]</a></td>
<td bgcolor=eeeeee><font color=black size=1 face=tahoma> $line[2]</td>
</tr>&quot;;
$clr=&quot;d&quot;;
}
else
{
echo &quot;<tr>
<td bgcolor=dddddd align=right><font color=black size=1 face=tahoma>$num.</td>
<td bgcolor=dddddd><font color=black size=1 face=tahoma> <a href=$line[1] target=_new>$line[0]</a></td>
<td bgcolor=dddddd><font color=black size=1 face=tahoma> $line[2]</td>
</tr>&quot;;
$clr=&quot;l&quot;;
}
}
echo &quot;</table>&quot;;
}



?>
<br><br>
<b>add a link</b><br>
<table border=0>
<form method=&quot;post&quot; action=&quot;add.php&quot;>
<tr>
<td align=right><font color=black size=1 face=tahoma>site name:</td>
<td align=right><input type=&quot;text&quot; name=&quot;name&quot; maxlength=&quot;15&quot; size=&quot;15&quot;></td>
</td>
<tr>
<td align=right><font color=black size=1 face=tahoma>url:</td>
<td align=right><input type=&quot;text&quot; name=&quot;url&quot; size=&quot;15&quot; value=&quot;</tr>
<tr>
<td align=right><font color=black size=1 face=tahoma>description:</td>
<td align=right><input type=&quot;text&quot; name=&quot;desc&quot; maxlength=&quot;15&quot; size=&quot;15&quot;></td>
</tr>
<tr>
<td></td>
<td align=right><input type=&quot;submit&quot; value=&quot;submit&quot;></form></td>
</tr>
</table>
</center>






in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
could try using the strip_tag function:
Code:
$string = strip_tags($string, '<a><b><i><u>');

t_avatar.jpg

'... and then it wouldn't compile?'
 
omg is that all?! score!! i take it the <a><i> and stuff is the excluded tags! you rock thanks! ;D

in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
You can use the optional second parameter to specify tags which should not be stripped

t_avatar.jpg

'... and then it wouldn't compile?'
 
thanks it worked :D i think o.0 hehe i tried braken my link thing and it didnt work even with the <!-- tag .. thanks :D

in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
Another possible solutions is using the htmlentities() function or htmlspecialchars(). But the best way is to do it using your own function, because this functions can sometime mess up some things. I usually use this.
Code:
function replace_html_chars($string) {
  $string=str_replace(&quot;<&quot;,&quot;&lt;&quot;,$string);
  $string=str_replace(&quot;>&quot;,&quot;&gt;&quot;,$string);
  $string=str_replace(&quot;&&quot;,&quot;&amp;&quot;,$string);
  // etc.
  return $string;
}
 
Hehe, function was messed up the same way we are trying to solve :D, see the fixed function:
Code:
function replace_html_chars($string) {
  $string=str_replace(&quot;<&quot;,&quot;&amp;lt;&quot;,$string);
  $string=str_replace(&quot;>&quot;,&quot;&amp;gt;&quot;,$string);
  $string=str_replace(&quot;&&quot;,&quot;&amp;amp;&quot;,$string);
  // etc.
  return $string;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top