Issue
Example user input
http://example.com/
http://example.com/topic/
http://example.com/topic/cars/
http://www.example.com/topic/questions/
I want a PHP function to make the output like
example.com
example.com/topic/
example.com/topic/cars/
www.example.com/topic/questions/
Solution
You should use an array of "disallowed" terms and use strpos
and str_replace
to dynamically remove them from the passed-in URL:
function remove_http($url) {
$disallowed = array('http://', 'https://');
foreach($disallowed as $d) {
if(strpos($url, $d) === 0) {
return str_replace($d, '', $url);
}
}
return $url;
}
Answered By - Jacob Relkin Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.