I want to replace specific words between <loc> and </loc> then limit the word to Specific number.
<?php
$string = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>https://subdomain.example.com</loc>
<priority>1.0</priority>
<changefreq>always</changefreq>
</url>
<url>
<loc>https://subdomain.example.com/s/queen-katwe-2016-720p-hd-480p-hd/</loc>
<priority>1.0</priority>
<changefreq>always</changefreq>
</url><url>
<loc>https://subdomain.example.com/s/justice-league-dark-2017-720p-hd-480p-hd/</loc>
<priority>1.0</priority>
<changefreq>always</changefreq>
</url><url>
<loc>https://subdomain.example.com/s/edge-seventeen-2016-720p-hd-480p-hd/</loc>
<priority>1.0</priority>
<changefreq>always</changefreq>
</url></urlset>';
$search = "/(<loc>)(.*?)(<\/loc>)/";
$replace = mb_strimwidth('$2', 0, 15);
$total = preg_replace($search,$replace,$string);
echo $total;
?>
I have tried and its not working... please kindly help me out, thank you in advance