<?php
$thisid= '{7370418c-3e5a-b044-8db3-4bba6d805f72}';
$elementId = 'a test working!';
$thisurl = 'This is {7370418c-3e5a-b044-8db3-4bba6d805f72}';
function getElementPath($elementId, $thisid, $thisurl)
{
return preg_replace(sprintf('/%s$/', $thisid), $elementId, $thisurl);
}
function getElementPathFixed($elementId, $thisid, $thisurl)
{
return preg_replace(sprintf('/%s$/', preg_quote($thisid)), $elementId, $thisurl);
}
// The problem
var_dump(getElementPath($elementId, $thisid, $thisurl));
// The fix
var_dump(getElementPathFixed($elementId, $thisid, $thisurl));
preferences:
25.86 ms | 407 KiB | 5 Q