Joanna Mikalai Joanna Mikalai - 2 months ago 5x
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; ?>

$str = '';
$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?