Joanna Mikalai Joanna Mikalai - 8 months ago 36
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?