Philippines military jets fired rockets at militant positions on Saturday as soldiers fought to wrest control of a southern city from gunmen linked to the Islamic State group, witnesses said.

Civilians waved flags from their windows to show they are not combatants.

The city of Marawi, home to some 200,000 people, has been under siege by IS-linked militants since a failed raid on Tuesday night on a suspected hideout of Isnilon Hapilon, who is on Washington's list of most-wanted terrorists.

Hapilon got away and fighters loyal to him took over parts of the city, burning buildings and seizing about a dozen hostages, including a priest. Their condition was not known.

At least 44 people have died in the fighting, including 31 militants and 11 soldiers, officials said. It was not clear whether civilians were among the dead.

The violence prompted President Rodrigo Duterte on Tuesday to declare 60 days of martial law in the southern Philippines, where a Muslim rebellion has raged for decades. But the recent violence has raised fears that extremism could be growing as smaller militant groups unify and align themselves with the ideology of IS.

Although Hapilon and other groups in the southern Philippines have pledged allegiance to IS, there is no clear sign of significant, material ties.

Thousands of civilians have been fleeing.

"I saw two jets swoop down and fire at rebel positions repeatedly," security guard Alexander Mangundatu told the Associated Press in Marawi as a plume of black smoke billowed in the distance.

"I pity the civilians and the women who were near the targeted area. They're getting caught in the conflict and I hope this ends soon."

Military spokesman Brigadier General Restituto Padilla said government forces are working to "clear the city of all remnants of this group".

He said some civilians had refused to evacuate because they want to guard their homes, slowing down the government operations.

"But that's fine as long as civilians are not hurt," he added.

On Friday, Mr Duterte ordered his troops to crush the militants, warning that the country is at a grave risk of "contamination" by IS.

He told soldiers in Iligan, a city near Marawi, that he had long feared that "contamination by Isis" loomed in the country's future, using the acronym for IS.

"You can say that Isis is here already," he said.

Lieutenant General Carlito G Galvez Jr, a military commander, said civilians are enduring "extreme deprivation" because government services are unavailable and shops are closed.

"These terrorist atrocities continue to sow terror and confusion even to non-combatant Muslims and Christians," he said in a statement.

Hapilon is still hiding out in the city under the protection of gunmen who are desperately trying to find a way to extricate him, said the Philippines' military chief, General Eduardo Ano. He said Hapilon suffered a stroke after a government air strike wounded him in January.

Gen Ano predicted that the military operation will take about a week as soldiers go from house to house to clear the city of militants.

In a sign that the long-standing problem of militancy in the south could be expanding, Solicitor General Jose Calida said foreigners were fighting alongside the gunmen in Marawi, including Indonesians and Malaysians.

Gen Ano also said foreign fighters were believed to be inside, but he was more cautious. "We suspect that, but we're still validating," he said.

Hapilon, an Islamic preacher, is a commander of the Abu Sayyaf militant group who pledged allegiance to IS in 2014. He also heads an alliance of at least 10 smaller militant groups, including the Maute, which have a heavy presence in Marawi and were instrumental in fighting off government forces in this week's battles.

Washington has offered a 5 million US dollars reward for information leading to Hapilon's capture.