Joanna Mikalai Joanna Mikalai - 1 year ago 110
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 Source
$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?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download