how to replace repeated spaces in php

Posted on July 30th, 2010 in programming, web | 2 Comments »


function replace_repeated_spaces($string)
{
	// tabs, new lines and carriages are also replaced
$string = ereg_replace("[ \t\n\r]+", " ", $string);
return $string;
}

$string = "This
   is
a   dummy
text. ";
$new_string = replace_repeated_spaces($string);
// Outputs: This is a dummy text

ereg_replace is almost deprecated from PHP, better to use preg_replace instead. And even when you will change to preg_replace this code will be 5 times slower than
while (strpos(‘ ‘, $string) !== false) $string = str_replace(‘ ‘, ‘ ‘, $string);
So the main idea is: “When you can write your code in a couple of lines without regular expressions – do it.

speachless

Posted on December 8th, 2009 in life, people | 1 Comment »

i am in a constant battle with my mind. i go from thinking that i am special for being “intelligent” to realizing that being aware of my being special is, in fact a sign that i am just seeking attention and simply something i like thinking about myself. then i realize that being aware of that fact counter-acts itself, and i am stuck in an endless paradox of myself. i have not yet learned how to stop and just say “it doesn’t matter”

Talk doesn’t cook rice

Posted on November 25th, 2009 in people | 1 Comment »

1. Don’t overthink. Too much thinking often results in getting stuck, in going in circles. Some thinking is good — it’s good to have a clear picture of where you’re going or why you’re doing this — but don’t get stuck thinking. Just do.
2. Just start. All the planning in the world will get you nowhere. You need to take that first step, no matter how small or how shaky. My rule for motivating myself to run is: Just lace up your shoes and get out the door. The rest takes care of itself.
3. Forget perfection. Perfectionism is the enemy of action. Kill it, immediately. You can’t let perfect stop you from doing. You can turn a bad draft into a good one, but you can’t turn no draft into a good draft. So get going.
4. Don’t mistake motion for action. A common mistake. A fury of activity doesn’t mean you’re doing anything. When you find yourself moving too quickly, doing too many things at once, this is a good reminder to stop. Slow down. Focus.
5. Focus on the important actions. Clear the distractions. Pick the one most important thing you must do today, and focus on that. Exclusively. When you’re done with that, repeat the process.
6. Move slowly, consciously. Be deliberate. Action doesn’t need to be done fast. In fact, that often leads to mistakes, and while perfection isn’t at all necessary, neither is making a ridiculous amount of mistakes that could be avoided with a bit of consciousness.
7. Take small steps. Biting off more than you can chew will kill the action. Maybe because of choking, I dunno. But small steps always works. Little tiny blows that will eventually break down that mountain. And each step is a victory, that will compel you to further victories.
8. Negative thinking gets you nowhere. Seriously, stop doing that. Self doubt? The urge to quit? Telling yourself that it’s OK to be distracted and that you can always get to it later? Squash those thoughts. Well, OK, you can be distracted for a little bit, but you get the idea. Positive thinking, as corny as it sounds, really works. It’s self-talk, and what we tell ourselves has a funny habit of turning into reality.
9. Meetings aren’t action. This is a common mistake in management. They hold meetings to get things done. Meetings, unfortunately, almost always get in the way of actual doing. Stop holding those meetings!
10. Talking (usually) isn’t action. Well, unless the action you need to take is a presentation or speech or something. Or you’re a television broadcaster. But usually, talking is just talking. Communication is necessary, but don’t mistake it for actual action.
11. Planning isn’t action. Sure, you need to plan. Do it, so you’re clear about what you’re doing. Just do it quickly, and get to the actual action as quickly as you can.
12. Reading about it isn’t action. You’re reading an article about action. Ironic, I know. But let this be the last one. Now get to work!
13. Sometimes, inaction is better. This might be the most ironic thing on the list, but really, if you find yourself spinning your wheels, or you find you’re doing more harm than good, rethink whether the action is even necessary. Or better yet, do this from the beginning — is it necessary? Only do the action if it is.

“Talk doesn’t cook rice.” - Chinese Proverb

morning elegance

Posted on June 19th, 2009 in fun, web | Comments Off

nota

Posted on January 23rd, 2009 in fun, ro | Comments Off

“Draga jurnalule. Nu am mai scris nimic de mult timp. Am fost depresiv. S-a mai terminat un an, iar n-am adus apocalipsa.”

more here

Don’t judge too quickly!

Posted on January 21st, 2009 in fun, movies | 2 Comments »

squeek

Posted on January 15th, 2009 in life, web | Comments Off

Yahoo! news in Gmail

Posted on January 13th, 2009 in web | Comments Off

this morning in my gmail acount.

…o frauda estimata la 50 mld. dolari.

Posted on December 16th, 2008 in Events, financial | 3 Comments »

more here

mens washroom

Posted on December 12th, 2008 in fun, life | 3 Comments »

Making it more fun :)