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