473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Insensitive Case for str_replace

TheServant
1,168 Expert 1GB
Well after many hours of writting a "sanitizing" function I have discovered I do not have stri_replace installed or something. I don't really want to search for WHERE, WhERE, WheRE... and so on, just to remove WHERE for MySQL input, does anyone have an idea how I could get around it?

I was using ronverdonk's code:
[PHP]str_ireplace( array(" ", "/",",","'","*","and","or","where"),'', 'WHERE This IS a TeSt.' ) );[/PHP]
Mar 16 '08 #1
4 1593
ronverdonk
4,258 Expert 4TB
When you do not have PHP5, you can use your own str_ireplace function. Thanks to n00b at battleofthebits in the PHP documentation. [php]if (!function_exists('str_ireplace') {
function str_ireplace($search,$replace,$subject) {
$token = '^[[term^]';
$haystack = strtolower($subject);
$needle = strtolower($search);
while (($pos=strpos($haystack,$needle))!==FALSE) {
$c++;
$subject = substr_replace($subject,$token,$pos,strlen($search ));
$haystack = substr_replace($haystack,$token,$pos,strlen($searc h));
}
while (($pos=strpos($subject,$token))!==FALSE) {
$subject = substr_replace($subject,$replace,$pos,strlen($toke n));
}
return $subject;
}
} [/php]Ronald
Mar 16 '08 #2
TheServant
1,168 Expert 1GB
Actually I found this:
[PHP]eregi_replace( array(" ", "/",",","'","*","and","or","where"),'', 'WHERE This IS a TeSt.' )[/PHP]

And it works except for the pattern to replace. In there it is an array, but I believe it needs to be in another form.
[PHP]eregi_replace( "where",'', 'WHERE This IS a TeSt.' )[/PHP]
works, and the php manual says it has to be a POSIX extended regular expression, so, I can do single characters, but not a set of character or a set of words. Any advice or hints?
Mar 16 '08 #3
ronverdonk
4,258 Expert 4TB
No hints. But why don't you want to use the str_ireplace function I posted instead of using a reg exp?

Ronald
Mar 16 '08 #4
TheServant
1,168 Expert 1GB
No hints. But why don't you want to use the str_ireplace function I posted instead of using a reg exp?

Ronald
Because if I do, it converts all the string to lower. I want to retain capitals in names. Acually, I have just thought about a problem. Say someone's name is "Wherever_you_go" that will remove it? I might ahve to think of a better system which allows that. The reg exp doesn't need to convert to lowercase.
Mar 16 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: -= Patrick =- | last post by:
Hi, I'm trying to replace strings in a body of html. These strings may contain spaces. str_replace works perfectly, except that it is case-sensitive. I've tried using eregi_replace, but I think...
3
by: cowboyx | last post by:
Is there a way to configure PHP to use case-insensitive variable names? I'd like to do this... $dbVars = pg_query( $connection, "SELECT columnName1, columnName2, columnName3 FROM table WHERE...
5
by: Madjid Nasiri | last post by:
Hi, I am basic in oracle. My Old programs write with Delphi and Databases: Access, Paradox, MySQL, Microsoft SQL. I write my code (SQL code) case-insensitivae, but now i need use oracle database....
12
by: Relaxin | last post by:
Is there a way to make Postgresql case-INSENSITIVE? Thanks
10
by: pamelafluente | last post by:
I need to replace all the occurences of a string within another string (or stringbuilder): Function ReplaceInsensitive(ByVal InputString As String, _ ByVal SubstringReplaced As String, _ ByVal...
1
by: benhoefer | last post by:
I have been searching around and have not been able to find any info on this. I have a unique situation where I need a case sensitive map: std::map<string, intimap; I need to be able to run a...
7
by: Adrian | last post by:
Hi, I want a const static std::set of strings which is case insensitive for the values. So I have the following which seems to work but something doesnt seem right about it. Is there a better...
4
by: bb | last post by:
Hi, void fun(const std::map<std::string,int>& m1) { // How to make a case insensitive search of this map without making a copy? } cheers.
0
by: J. Cliff Dyer | last post by:
Please keep the discussion on-list. On Fri, 2008-09-05 at 15:36 +0200, Maric Michaud wrote: That does not get the same behavior as the OP's original solution. The OP's solution retrieves the...
2
by: Alex Weber | last post by:
weird issue i ran into today... its possible to define case-insensitive constants outside the scope of a class using: define('name', 'value', false); however, you cannot use define() for...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.