Chris wrote:
Rafael wrote:
Hi Chris,
if the only thing you want is to get the domain (having the whole
URL) you have more than one way to solve it. Chris -it's a little
akward that Chris answered to Chris- already told you about
parse_url(), and since we're talking about strings, I would suggest
something like
$domain = preg_replace('{^([a-z]+://[^/]+).*$}X', '%1', $uri);
We are two different people !? Not sure how that's difficult.
Did I say difficult? What I meant is that seing a question from Chris,
immediately followed by a message from Chris leds to think it's an
"extension" of the question (maybe something he forgot, or something
new), but it wasn't, it was an answer from (a different) Chris, hence a
little akward.
--I hope this makes things clear for you.
I don't know why you'd use a regular expression when you can use a
function instead (easier to maintain, it'll be faster, you won't make a
mistake)...
What I sent was a way to get what he wants in 1 function call. You
should understand that preg_* family functions are just like str_*
family functions, they work with strings, it's as simple as that -and
yes, they're functions too.
Now, probably parse_url() relies in preg_* or ereg_* functions -that
wouldn't be rare-, so I don't think parse_url() would be faster than
preg_replace(), and even if it is the difference would be meaningless;
and neither I see how writing more lines would be faster. I also would
like to know how the use of parse_url() would guarantee that he won't
make a mistake.
Man, I can only conclude you've satanized preg_* functions because of a
lack of knowledge, and I suggest you to investigate more about them,
they're quite useful the same for easy and complex tasks. Someone said
once that you don't know the power of regexp until you know them, and
that's definetely true.
But of course there is always more than one way to solve a problem.
Agreed, so Chris may consider whatever he likes the most. If he, like
you, thinks that regular expressions are too complex and don't like the
idea of knowing them, then he will most likely choose parse_url() -which
is just fine.
--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
http://www.innox.com.mx
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php