President Rodrigo Duterte said Friday he will likely extend 60 days of martial law he imposed in the southern Philippines to deal with a deadly siege of a city by militants allied with the Islamic State group because the situation remains critical.

Duterte said he would only lift martial rule, which is to expire in about two weeks, if the military and police tell him the danger posed by the militants has abated. The Supreme Court upheld his martial law declaration on Tuesday in a legal boost to the military offensive he ordered to quell the Marawi city siege.

Duterte has said the offensive is winding down and could end soon in Marawi, which was attacked by hundreds of gunmen waving IS-style black flags on May 23. But scores of gunmen are still holding hostages and continuing to fight in four areas of the lakeside city, a bastion of the Islamic faith in the south.

Asked if he plans to lift martial law this month, Duterte said he consulted the military and police and was told the situation remains critical. He said he would rely on their advice because "they are the ones keeping this republic healthy and alive."

"If they say there is no more danger and everything is OK, then that is the time that we will lift martial law," Duterte said.

Carrying an assault rifle and wearing a military camouflage uniform, Duterte attempted but failed to fly to Marawi to visit troops Friday due to bad weather. It was his second aborted trip to the predominantly Islamic city, large areas of which resemble a smoldering war zone amid intense fighting and military airstrikes.

"I should show my face there," Duterte said, adding he wants to visit during the fighting to demonstrate his desire "to protect the republic."

Security officials hope the crisis will end before Duterte delivers his annual state of the nation address on July 24, but Defense Secretary Delfin Lorenzana has said he will let commanders set the pace of the battle to avoid adding pressure that could endanger troops.

More than 350 militants, 87 soldiers and police and 39 civilians have been killed in 46 days of fighting, alarming Southeast Asian and Western governments, which fear that the Islamic State group's rule in Syria and Iraq, now collapsing, may have galvanized Asian militants into attempting to create their own so-called Islamic caliphate.

The United States and Australia have deployed surveillance planes to Marawi to help Filipino troops locate the remaining militants holed up in buildings and houses.

Nearly 400,000 residents have abandoned Marawi and outlying towns in Lanao del Sur province, about 800 kilometers (500 miles) southeast of Manila.