- preg_match: documentation ( source)
- str_replace: documentation ( source)
<?php
$b= 1234;
$your_variable = '<input name="LFMIdsite" value="8635" type="hidden">';
$result = preg_match('/name="LFMIdsite" value="(.*?)"/', $your_variable, $matches);
$lidsite = $matches[1];
echo $lidsite;
$your_variable = str_replace('/name="LFMIdsite" value="'.$lidsite.'"', '/name="LFMIdsite" value="'.$b.'"', $your_variable);
echo $your_variable;