remove http and https from string in php
This worked for me,
$http_referer = str_replace($removeChar, "", "https://example.com/");
How to remove 'http://' from a URL in JavaScript
I think it would be better to take into account all possible protocols.
result = url.replace(/(^\w+:|^)\/\//, '');
How to remove www, http/https and other strings in URL in C#
If you are working for Winforms then
string url = "http://www.merriam-webster.com/dictionary/sample";
UriBuilder ub = new UriBuilder(url);
MessageBox.Show(ub.Host.Replace("www.",""));
and for web,
Get host domain from URL?
Remove http:// and https:// from a string
server = server.(/^https?\:\/\/(www.)?/,'')
This didn't work, because you aren't calling a method of the string server
. Make sure you call the sub
method:
server = server.sub(/^https?\:\/\/(www.)?/,'')
Example
> server = "http://www.stackoverflow.com"
> server = server.sub(/^https?\:\/\/(www.)?/,'')
stackoverflow.com
As per the requirement if you want it to work with the illegal format http:\\
as well, use the following regex:
server.sub(/https?\:(\\\\|\/\/)(www.)?/,'')
PHP Regex to Remove http:// from string
$str = 'http://www.google.com';
$str = preg_replace('#^https?://#', '', $str);
echo $str; // www.google.com
That will work for both http://
and https://
Remove www , http:// from string
s = s.sub(/^https?\:\/\//, '').sub(/^www./,'')
If you don't want to use s =
, you should use sub!
s instead of all sub
s.
The problems with your code are:
- Question mark always follows AFTER an optional character
- Always replace one pattern in a sub. You can "chain up" multiple operations.
- Use
sub
instead ofgsub
and^
in the beginning of Regexp so it only replaces thehttp://
in the beginning but leaves the ones in the middle.
How can I remove http or https using javascript
To remove just http
/https
: window.location.href.replace(/^http(s?)/i, "");
To remove http:
/https:
: window.location.href.replace(/^http(s?):/i, "");
To remove http://
/https://
: window.location.href.replace(/^http(s?):\/\//i, "");
These are all case-insensitive and only remove from the start of the string
Related Topics
Differencebetween "Rails S" and "Bundle Exec Rails S"
Routing Error - Uninitialized Constant
Retrieve Contents of Url as String
Ruby: No Such File or Directory @ Rb_Sysopen - Testfile (Errno::Enoent)
Don't Have Jekyll-Paginate or One of Its Dependencies Installed
Truncate String to the First N Words
How to Reference a Lambda from Within Itself Using Ruby
Nokogiri Error When Running Bundle Install
Strategies for Overriding Database.Yml
How to Include a Yaml File Inside a Yaml File in Ruby
Rake Assets:Precompile Gets Killed When There Is a Console Session Open in Production
What Does the Regular Expression [\W-] Mean
Pry Not Stopping When Called from a Ruby Script That Reads from Stdin
Why Is This Permissions Error Occurring with Mod_Passenger.So
Call Task More Than Once in Rails 3 Generator
Url_For of a Custom Restful Resource (Composite Key; Not Just Id)
Ruby Model Output Id as Object Oid
Spork 0.9.2 and Rspec 3.0.0 = Uninitialized Constant Rspec::Core::Commandline (Nameerror)