php - Insert string into specific part of another string -


i've got url string, example:

http://example.com/sub/sub2/hello/ 

i'd add subfolder php, before hello, should this:

http://example.com/sub/sub2/sub3/hello/ 

i thought using explode separate url slashes, , adding 1 before last one, i'm pretty sure on complicate it. there easier way?

this should work you:

(here put folder between basename() , dirname() of string right before last part of url)

<?php      $str = "http://example.com/sub/sub2/hello/";     $folder = "sub3";      echo dirname($str) . "/$folder/" . basename($str);  ?> 

output:

http://example.com/sub/sub2/sub3/hello 

Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -