How do I use preg_replace
text/url. For example, I have a url like this: http://www.web.org/dorama/1201102144/hitoya-no-toge
. I just want to show web.org
. The url is not always same, for example sometimes it's: http://www.web.org/movies/123/no
etc.
I only know the basics of it. Here is what I tried. It still does not delete the slash
.
$url = "http://www.web.org/dorama/1201102144/hitoya-no-toge";
$patterns = array();
$patterns[0] = '/http:/';
$patterns[1] = '/dorama/';
$patterns[2] = '/1201102144/';
$replacements = array();
$replacements[2] = '';
$replacements[1] = '';
$replacements[0] = '';
echo preg_replace($patterns, $replacements, $url);
result when i run it //www.web.org///hitoya-no-toge