Renlok Posted January 29, 2009 Share Posted January 29, 2009 is there another way of doing case insenstitive string replaces other than with str_ireplace? Im making a open source script and for the word filter i need it to be case insensitive but i dont want to use str_ireplace as its a php5 function and i want it to work on php4 anyone have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/ Share on other sites More sharing options...
.josh Posted January 29, 2009 Share Posted January 29, 2009 could use preg_replace. Quote Link to comment https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749742 Share on other sites More sharing options...
Renlok Posted January 29, 2009 Author Share Posted January 29, 2009 yes that works fine thakyou Quote Link to comment https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749749 Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 i am not sure but has php4 got to have preg_replace enabled in php.ini if so use eregi_replace() Quote Link to comment https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749756 Share on other sites More sharing options...
Daniel0 Posted January 29, 2009 Share Posted January 29, 2009 i am not sure but has php4 got to have preg_replace enabled in php.ini Yes. if so use eregi_replace() No. Quote Link to comment https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749762 Share on other sites More sharing options...
.josh Posted January 29, 2009 Share Posted January 29, 2009 i am not sure but has php4 got to have preg_replace enabled in php.ini if so use eregi_replace() Yes preg_replace is enabled by default. Don't use eregi_replace or any posix functions (ereg_xxx) as they are not going to be part of the core as of php6. Why? Because they are stupid and inferior. Quote Link to comment https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749766 Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 if you want the letters to be uppercase then use strtoupper() function. <?php $letters="abcdefg"; echo" ".strtoupper($letters).""; ?> yes dont use eregi due to it being tured off in php6 but your working on a php4 script i notice or is it a script that can be used on php4 and php5 and php6 if so use preg_repalce() Quote Link to comment https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749768 Share on other sites More sharing options...
.josh Posted January 29, 2009 Share Posted January 29, 2009 okay redarrow, but if you strtoupper then you won't preserve the case of the rest of the string. Quote Link to comment https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749780 Share on other sites More sharing options...
Daniel0 Posted January 29, 2009 Share Posted January 29, 2009 yes dont use eregi due to it being tured off in php6 but your working on a php4 script i notice or is it a script that can be used on php4 and php5 and php6 if so use preg_repalce() Could you rephrase that, please? It's not legible. Quote Link to comment https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749819 Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 here a example mate encase you dont no how to get it to work. like i say still got to use strtoupper mate <?php $letters="abcdefg"; $letters = preg_replace("/[A-Za-z]/e", 'strtoupper("$0")', $letters, 100); echo $letters; ?> dan all i am saying is that if the user is going to create a script for php4 only then he can use eregi_relace() Quote Link to comment https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749830 Share on other sites More sharing options...
.josh Posted January 29, 2009 Share Posted January 29, 2009 there's no such thing as an 'e' modifier. I assume maybe you meant 'i' except that you already cover capital and lower case in your char class so really, I have no idea what you intended to do with that 'e' Quote Link to comment https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749835 Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 When using the e modifier, this function escapes some characters (namely ', ", \ and NULL) in the strings that replace the backreferences. This is done to ensure that no syntax errors arise from backreference usage with either single or double quotes (e.g. 'strlen(\'$1\')+strlen("$2")'). Make sure you are aware of PHP's string syntax to know exactly how the interpreted string will look like. Seems a stripslashes to finish up is what you need. Regards, Quote Link to comment https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749841 Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 there is a e modifier just for backslash yes can use \\ Quote Link to comment https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749846 Share on other sites More sharing options...
Daniel0 Posted January 29, 2009 Share Posted January 29, 2009 dan all i am saying is that if the user is going to create a script for php4 only then he can use eregi_relace() But he could also use the PCRE functions, which he, according to the manual, should. That is assuming he is using 4.2+, but seeing as support for the 4.x branch is discontinued and the latest PHP4 version is 4.4.9 it would be logical to assume that's not the case. <?php $letters="abcdefg"; $letters = preg_replace("/[A-Za-z]/e", 'strtoupper("$0")', $letters, 100); echo $letters; ?> That's a stupid example and what is it even supposed to be showing? Quote Link to comment https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749850 Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 http://us3.php.net/manual/en/reference.pcre.pattern.modifiers.php look e up mate it there. Quote Link to comment https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749851 Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 so what your solution i ant got another with preg_repalce show us mate. Quote Link to comment https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749854 Share on other sites More sharing options...
.josh Posted January 29, 2009 Share Posted January 29, 2009 ah that's a preg_replace only modifier. Okay but still, I don't really see why you need that in there. Quote Link to comment https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749860 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.