JoaMika
JoaMika

Reputation: 1827

Remove http:// or https:// from variable

I am using this code to remove the http:// part of a URL but it doesn't do anything - it just returns the full URL. What am I doing wrong?

<?php $str = the_field('fl_website');$str = preg_replace('#^https?://#', '', rtrim($str,'/'));echo $str; ?>

Upvotes: 0

Views: 71

Answers (1)

Whencesoever
Whencesoever

Reputation: 2296

$str = 'http://www.google.com';
$str = preg_replace('#^https?://#', '', $str);

I can see You are doing it similiar way. Maybe the variable is not set as You think it is?

Upvotes: 2

Related Questions