This is url stored in variable
I want to remove text between fifth and sixth occurrence of “/” (106-a3-297-x-42cm-2) and one /
Output should look like this:
How can I achieve this?
Advertisement
Answer
You an do it by many ways,. One way to achieve this way using parse_url()
,
JavaScript
x
<?php
$url = 'https://photoland2.etrafficgroup.com.au/frames-and-albums/frames/wooden-frames/106-a3-297-x-42cm-2/product/555-black-wooden-frame-with-gold-stripe-a3-42x29-7cm-size-1-7cm-wide/';
$initial = parse_url($url);
$result = array_filter(explode('/',parse_url($url)['path']));
unset($result[4]);
$filtered = implode('/',$result);
echo $initial['scheme'].'://'.$initial['host'].'/'.$filtered.'/';
?>
DEMO: https://3v4l.org/60rZB