env3rt Posted October 5, 2007 Share Posted October 5, 2007 I'm making my own htmlEntities thingy because I want certain codes to work and others not to. The problem is that if I ban < br > then you can still do things like < BR > and stuff <?php function htmlfilter($badcodes){ $filout = array( "<br>","<BR>","<Br>","<bR>","<P>","<p>" ); $nobadcodes = "<nocode>"; foreach($filout as $replace){ $badcodes = str_replace($filout,$nobadcodes,$badcodes); } return $badcodes; } ?> So basically I need something to ignore capital letters, because I don't want to type every possible combination of capital letters and normal letters for each code (like above) Please help, ask if you need further information. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted October 5, 2007 Share Posted October 5, 2007 stri_replace() Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 5, 2007 Author Share Posted October 5, 2007 stri_replace() ? Quote Link to comment Share on other sites More sharing options...
Yesideez Posted October 5, 2007 Share Posted October 5, 2007 Sorry, I meant str_ireplace() Â http://us.php.net/manual/en/function.str-ireplace.php Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2007 Share Posted October 5, 2007 I'm making my own htmlEntities thingy because I want certain codes to work and others not to. Â an existing function already provides for this: Â strip_tags ( string $str [, string $allowable_tags] ) Â $content = strip_tags($content); Â if you want to allow <UL> and <LI>, for instance, Â $content = strip_tags($content, '<UL><LI>'); Â Â Â ah, but this doesn't replace does it?? never mind.. Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 5, 2007 Author Share Posted October 5, 2007 [code=]<?php function htmlfilter($badcodes){ $filout = array( "<br>","<p>" ); $nobadcodes = "<nocode>"; foreach($filout as $ireplace){ $badcodes = str_ireplace($filout,$nobadcodes,$badcodes); } return $badcodes; } ?> Would that be what you do just replace the to "replace"'s with ireplace? Because it's not working Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2007 Share Posted October 5, 2007 remove the for, we're sending the whole array in one shot: Â function htmlfilter($badcodes){ Â Â $filout = array("<br>","<p>"); Â Â $nobadcodes = "<nocode>"; return str_ireplace($filout,$nobadcodes,$badcodes); } Quote Link to comment Share on other sites More sharing options...
Yesideez Posted October 5, 2007 Share Posted October 5, 2007 <?php function htmlfilter($badcodes){ Â $filout = array('<br>','<p>'); Â $nobadcodes = '<nocode>'; Â $badcodes=str_ireplace($filout,$nobadcodes,$badcodes); Â return $badcodes; } ?> Â Try that. I enclosed the text with single quotes instead of double. Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 5, 2007 Author Share Posted October 5, 2007 remove the for, we're sending the whole array in one shot: Â function htmlfilter($badcodes){ Â Â $filout = array("<br>","<p>"); Â Â Â $nobadcodes = "<nocode>"; return str_ireplace($filout,$nobadcodes,$badcodes); } That's not working <?php function htmlfilter($badcodes){ Â $filout = array('<br>','<p>'); Â $nobadcodes = '<nocode>'; Â $badcodes=str_ireplace($filout,$nobadcodes,$badcodes); Â return $badcodes; } ?> Â Try that. I enclosed the text with single quotes instead of double. not working either Quote Link to comment Share on other sites More sharing options...
Yesideez Posted October 5, 2007 Share Posted October 5, 2007 Have you checked that your data is being passed to the function correctly? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2007 Share Posted October 5, 2007 yes, can we see at least a partial example of $badcodes? Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 5, 2007 Author Share Posted October 5, 2007 Well the original code worked properly so I assume that the other codes are wrong. Â Not sure what you mean by see partial example of $badcodes Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2007 Share Posted October 5, 2007 that is, can we see an example of what you are sending to the function to test it, the HTML? Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 5, 2007 Author Share Posted October 5, 2007 <?php include("htmlfilter.php"); $sig = $username."sig.html"; $fh = fopen($sig, 'r'); $sigpage = fread($fh, filesize($sig)); fclose($fh); if($_POST['sigupdate']) { $fh = fopen($sig, 'w'); $filterhtml = htmlfilter($signature); fwrite($fh, $filterhtml); fclose($fh); echo "<script type='text/javascript'> window.location = '/$username.php' </script>"; } echo" <center>Update your signature! <form method='post' action='?signature'> <textarea name='signature'>$sigpage</textarea> <input type='submit' value='Submit' name='sigupdate'> </form> Your sig is now:<br> $sigpage </center></marquee></font> "; ?> Â I would really like it if you could just switch the replace to ireplace from the original code for me because the original code was working, and I don't know how to do it Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 5, 2007 Author Share Posted October 5, 2007  I would really like it if someone could just switch the replace to ireplace from the original code for me because the original code was working, and I don't know how to do it  Please Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 5, 2007 Author Share Posted October 5, 2007 Fatal error: Call to undefined function: str_ireplace() Does that mean that str_ireplace doesn't work on my server? Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 5, 2007 Author Share Posted October 5, 2007 <?php function htmlfilter($badcodes){ Â $filout = array('<br>','<p>'); Â $nobadcodes = '<nocode>'; Â $badcodes=str_replace($filout,$nobadcodes,$badcodes); Â return $badcodes; } ?> Â that works but once I change the replace to ireplace it stops working Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2007 Share Posted October 5, 2007 Fatal error: Call to undefined function: str_ireplace() Does that mean that str_ireplace doesn't work on my server? Â yes, apparently so. it is a PHP 5 function and you probably have PHP 4. Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 5, 2007 Author Share Posted October 5, 2007 Damn so I guess I can't really do it properly then Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2007 Share Posted October 5, 2007 you can, but you'll have to use something less fun like preg_replace(). Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 5, 2007 Author Share Posted October 5, 2007 Could you show how to insert it into my code Or could you possibly disable capital letters Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted October 5, 2007 Share Posted October 5, 2007 you need  str_replace  it will work with php 5 and 4 Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 5, 2007 Author Share Posted October 5, 2007 you need  str_replace  it will work with php 5 and 4 Lol I have been using that all along but it is case sensitive and I don't want it to be, so they suggest str_ireplace but I have php 4 Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2007 Share Posted October 5, 2007 hence the correct solution: preg_replace() Â Â Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 5, 2007 Author Share Posted October 5, 2007 I don't understand preg_replace, well I do but not how I could use it to help, unless I switched all the caps letters to non caps Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.