PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too.
function replacecolons($mystring){
$mynewstring = str_replace(':', '-', $mystring );
return $mynewstring;
}
//call your function...
$gibberish = 'blahblah:blah';
$gibberish = replacecolons($gibberish);
//$gibberish now is blahblah-blah
I think that should work, although I don't have time to test it at the moment.
-OmniUni
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too.
It offers flexibility and less typing if you need to expand it later, say, to deal with semicolons as well. It can make code easier to read, by providing a more "English" command than having to interpret each time. If you decide to change what it does, make one change in the function, and it is reflected throughout the program, rather than having to modify every instance of a command.
Valid opinion I guess. To me though, it seems like he very specifically wants to just replace colons & adding another function just creates more overhead.
Obviously though, it's up to the original poster.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
The overhead is a good point. For me, at least, I try to do reusable code when I can simply because I'm not doing a lot of complicated things yet, and the overhead is far less of a concern to me than the fact that I often change my mind later about how I want to work with X Y or Z.