Joanna Mikalai Joanna Mikalai - 3 months ago 10
PHP Question

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; ?>

Answer
$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?