3v4l.org

run code in 300+ PHP versions simultaneously
<?php $url = 'www.example.com/title/page/article/'; //this is the URL $urlArray = explode('/', $url); //Strip down the URL $startURL = $urlArray[0]; //we want to keep this for if the user clicks on start. $urlArray[0] = 'Start'; //replace www.example.com with "start" if($urlArray[count($urlArray) - 1] == ''){ //this checks the last item is being empty or not. array_pop($urlArray); //last item is indeed empty so we just remove it. } $broadCrumb = ''; //create an empty broadCrumb variable Foreach($urlArray as $index =>$value){ //loop through the stripped down url $value = ucfirst($value); //initcap the items $broadCrumbTemp = '<a href="'.$startURL.'/{url}">{linkname}</a>{delimeter}'; //this is the template we are going to use. if($index == (count($urlArray) - 1)){ //if the index is last $broadCrumb .= $value; //just append the item }else{ //if the index isn't last $location = ''; for($i = 1; $i <= $index; $i++){ $location .= $urlArray[$i].'/'; } $replace = array('{url}', '{linkname}', '{delimeter}'); $replaceTo = array($location, $value, ' > '); $broadCrumbTemp = str_ireplace($replace, $replaceTo, $broadCrumbTemp); $broadCrumb .= $broadCrumbTemp; } } echo($broadCrumb); //show the broadCrumb
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.5 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
<a href="www.example.com/">Start</a> > <a href="www.example.com/title/">Title</a> > <a href="www.example.com/title/page/">Page</a> > Article

preferences:
233.19 ms | 404 KiB | 298 Q