I just read about a new crowdsoursing site and curious as I am i was checking which code gets the money.
I found a php task for a dollar. It's a nine line solution, with two updates, which does following things:
- parses the input
- looks for a specific key from the parsed array
- seaches for www. substring
- removes the www. substring if it's found
One solution uses str_ireplace, which is a step in the right direction.
What they needed to use is preg_replace.
$cleaned = preg_replace('#^(?:https?://)?(?:www.)?(.+)$#', '$1', $input);
The regex has three groups, two of them that aren't needed for the output.
One dollar of one line of code is still too low, I just gave it away for free.
No comments:
Post a Comment