Jump to content

add into a string other string


dsp77

Recommended Posts

All you need to do is work out the position of the far right "/" using strrpos, and then insert text between that point using substr:

 

$str = 'http://www.example.com/cat/name-of-article/5054673';

$pos = strrpos(rtrim($str, '/'), '/');
$str = substr($str, 0, $pos) . '/full_screen' . substr($str, $pos);

echo $str;

 

Notice the use of rtrim in-case there's a trailing slash.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.