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. Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/ Share on other sites More sharing options...
Yesideez Posted October 5, 2007 Share Posted October 5, 2007 stri_replace() Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362768 Share on other sites More sharing options...
env3rt Posted October 5, 2007 Author Share Posted October 5, 2007 stri_replace() ? Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362769 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 Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362772 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.. Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362774 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 Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362776 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); } Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362779 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. Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362782 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 Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362786 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? Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362791 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? Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362792 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 Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362795 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? Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362802 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 Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362807 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 Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362825 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? Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362840 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 Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362845 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. Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362847 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 Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362849 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(). Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362854 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 Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362857 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 Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362865 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 Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362871 Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2007 Share Posted October 5, 2007 hence the correct solution: preg_replace() Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362874 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 Link to comment https://forums.phpfreaks.com/topic/72009-solved-capital-letters-error/#findComment-362875 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.