$res_index = str_replace("<input type='hidden' name='k' value='",'***',$res_index); list($str1, $str2) = explode("***", $res_index); $str2 = str_replace("'>",'***',$str2); list($str1, $str12) = explode("***", $str2); $k = $str1;