rololo rololo - 1 month ago 7
PHP Question

How to remove two same and random characters following each other in string - PHP

Need to remove random

aa/
or
bb/
to
zz/
letters (with slash) to get
/logo/picture.png


$url = "/logo/aa/picture.png";
$url = "/logo/bb/picture.png";
$url = "/logo/cc/picture.png";

Answer

This is an alternative which doesn't care what's contained in that url part or what lengths url parts have:

$urlParts = explode('/', $url);
array_splice($urlParts, count($urlParts) - 2, 1);
$url = implode('/',  $urlParts);
Comments