Jump to content

help making the santax of strip_tags corect...


aftab_jii

Recommended Posts

hi...
i need some serious help with strip_tags..
i have copied follwing code from php.net

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
<?php
//tags.php

//Allow these tags
$allowedTags = '<u><i><b><a><img><br><p><table><tr><td><ul><li><pre><hr><blockquote>';

//Disallow these attributes/prefix within a tag
$stripAttrib = 'javascript:|onclick|ondblclick|onmousedown|onmouseup|onmouseover|'.
'onmousemove|onmouseout|onkeypress|onkeydown|onkeyup';

//remove evel tags
function removeEvilTags($source)
{
global $allowedTags;
$source = strip_tags($source, $allowedTags);
return preg_replace('/<(.*?)>/ie', "'<'.removeEvilAttributes('\\1').'>'", $source);
}

//remove evil arrtibutes
function removeEvilAttributes($tagSource)
{
global $stripAttrib;
return stripslashes(preg_replace("/$stripAttrib/i", 'forbidden', $tagSource));
}
?>
[/quote]

and now i want to apply the defined functions to the following echos:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<input id="searchkeywords" type="text" name="keywords"
<?php
if (isset($_GET['keywords'])) {
echo ' value="' . htmlspecialchars($_GET['keywords']) . '" ';
}
?>[/quote]

and

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<p> Body:<br>
<textarea class="body" name="body" rows="10" cols="60"><?php
echo htmlspecialchars($body); ?></textarea>
</p>[/quote]

I have tried doing it the following way:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
require_once('tags.php');
.
.
.
<input id="searchkeywords" type="text" name="keywords"
<?php
if (isset($_GET['keywords'])) {
echo ' value="' . removeEvilTags(htmlspecialchars($_GET['keywords']),TRUE) . '" ';
}
?>[/quote]

and

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
require_once('tags.php');
.
.
.
<p> Body:<br>
<textarea class="body" name="body" rows="10" cols="60"><?php
echo removeEvilTags($body, TRUE); ?></textarea>
</p>[/quote]

but its not correct since the search felt and the textarea still accepts the evilTags...

need help tp solve the problem...
i hope i get some quick answers soon...
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.