Jump to content

[SOLVED] preg_replace http:// in url.


ted_chou12

Recommended Posts

I tried to learn a bit, simple ones I understand, but hard ones I cant do, how do you replace the http:// in front of the url using preg replace?

$link = preg_replace("/^(http:\/\/)?(.*?)/i", "$1", $link);

This is what I got, it doesnt work at all.

I don't think is right anyways.

Thanks for your corrections.

Ted.

Link to comment
https://forums.phpfreaks.com/topic/76842-solved-preg_replace-http-in-url/
Share on other sites

sorry, I finally got it working... however, I am having a problem:

$links444 = preg_replace("`(http://)?(www.)?(.*?)`is", "$3", $link2);

for this code, when I tried wwww.domain.com, it strips the www. and becomes wdomain.com, I know I am bored , and picky, but is it possible to modify it a bit so that when there are wwww. or it detects something different, it doesn't remove the "www."? Thanks.

Ted

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.