To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
Code CritiqueHaving someone critique your code is always a great way to hone the skills. Stop in and post your code to see what your peers may have done differently.
Sort of a code share/critque here.
This is a small function to perform case-insensitive string replacements.
This is included in PHP 5, but I've seen a couple threads asking this kind of question and being pointed to eregi.
Maybe it's overkill.
Maybe I'm wasting time.
But this is for us eregi-illiterate folk
PHP Code:
<?php
function str_ireplace($find,$replace,$string) {
/* Create arrays for $find and $replace
If multiple $replace's are present, but
only one $find, it will replace $find
with only the first value in the
$replace array
*/
Needs a little more commenting, probably...very good code! Just kind of a waste of time to reinvent the wheel, methinks.
Just one quick question: why do you need to unset $replace?
(No, I'm not hijacking this thread )
__________________
"A proof is a proof. What kind of a proof? It's a proof. A proof is a proof. And when you have a good proof, it's because it's proven." -- Jean Chrétien
I can paint a house with a 1 inch brush or a paint sprayer. I don't know many people that would choose to use the 1 inch brush, but I'm sure there's someone out there.
Seems your code is more of an exercise for you rather than a replacement for preg_replace. I doubt there is anyone out there that has learned PHP that would choose to say "no, I don't think I want to learn regex." But as with my previous example, I could be wrong...
Originally posted by BuzzLY I can paint a house with a 1 inch brush or a paint sprayer. I don't know many people that would choose to use the 1 inch brush, but I'm sure there's someone out there.
Seems your code is more of an exercise for you rather than a replacement for preg_replace. I doubt there is anyone out there that has learned PHP that would choose to say "no, I don't think I want to learn regex." But as with my previous example, I could be wrong...
True, Buzz. Methinks that some people like the 'adrenaline rush' of painting with a one-inch brush. not much of an adrenaline rush, i know, but maybe LShryku got a kick out of coding this. Nonetheless, regex is a lot more powerful...now, if LShryku were to create a LordShrykuRegex, that would be different (throwing ideas at you). And, if he were to bundle it as a LordShryku extension, that would be supercool, but I don't think LordShryku would bother doing that...besides, the code shows good coding skills! This is more of a code share, but it might give someone ideas to make their own functions...and maybe one day there'll be a MerveRegex...i dunno The point is that this may be a pointless exercise, but not everything has to have a purpose. Sometime we need to get away from that.
The only critique i have is that maybe you should comment every few lines instead of using one big comment at the top, since the code ain't that long...methinks it'd be a good idea, but wouldn't improve functionality, so why bother?
__________________
"A proof is a proof. What kind of a proof? It's a proof. A proof is a proof. And when you have a good proof, it's because it's proven." -- Jean Chrétien
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,127
A project for someone with way too much time on their hands:
MiniPHP
It's a chopped down version of PHP with the minimum of functionality required to implement all of it - all of PHP's functions are to be implemented, but as many as possible are to be implemented in PHP and included.
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.