I have this function which searches for strings like this:
<unique>342342342</unique>
<unique>5345345345345435345</unique>
<unique>4444</unique>
function:
$pattern = '/<unique>(.*?)<\/unique>/';
$response = preg_replace_callback($pattern,function($match){
$value = intval(trim($match[1])/200);
return '<unique>'.$value.'</unique>';
},$xml);
and change the number to its half (n/2). So far so good.
But I need to add a conditional to check if the number has more than 10 digits, if true then makes the change, if not, doesn't.
I tried this, but nope...all instances de '4444' get removed
$pattern = '/<unique>(.*?)<\/unique>/';
$response = preg_replace_callback($pattern,function($match){
$valueunique = trim($match[1]);
if(strlen($valueunique) >= 11){
$value = intval($valueunique/200);
return '<unique>'.$value.'</unique>';
}
},$xml);