How to concatenate string continuously in php? -
<?php      $test = ' /clothing/men/tees';      $req_url = explode('/', $test);      $c = count($req_url);      $ex_url = 'http://www.test.com/';      for($i=1; $c > $i; $i++){          echo '/'.'<a href="'.$ex_url.'/'.$req_url[$i].'">                  <span>'.ucfirst($req_url[$i]).'</span>              </a>';         //echo '<br/>'.$ex_url;....//last line     } ?>   output - 1 //when comment last line
/ clothing / men / tees   output - 2 //when un-comment last line $ex_url shows
/ clothing  http://www.test.com// men  http://www.test.com// tees  http://www.test.com/   1. required output -
in span - / clothing / men / tees , last element should not clickable
and link should created in way
http://www.test.com/clothing/men/tees -- when click on tees  http://www.test.com/clothing/men --  when click on men   ...respectively
2. output 2 why comes that
try this:
   <?php     $test = '/clothing/men/tees';     $url = 'http://www.test.com';     foreach(preg_split('!/!', $test, -1,  preg_split_no_empty) $e) {     $url .= '/'.$e;         echo '/<a href="'.$url.'"><span>'.ucfirst($e).'</span></a>';     }     ?>   output:
/clothing/men/tees   html output:
/<a href="http://www.test.com/clothing"><span>clothing</span></a>/<a href="http://www.test.com/clothing/men"><span>men</span></a>/<a href="http://www.test.com/clothing/men/tees"><span>tees</span></a>      
Comments
Post a Comment