Jump to content

[SOLVED] str_ireplace


Renlok

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749766
Share on other sites

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()

Link to comment
https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749768
Share on other sites

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()

Link to comment
https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749830
Share on other sites

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,

 

Link to comment
https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749841
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/142985-solved-str_ireplace/#findComment-749850
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.