WASHINGTON - Stung by his second major setback on immigration, President Donald Trump on Wednesday slammed as "ridiculous" a court order blocking his attempt to deny cities harbouring undocumented immigrants billions in federal funding.

Judge William Orrick of San Francisco's federal district court on Tuesday issued a preliminary injunction barring any attempt to implement Trump's January 25 executive order.

While confusing Orrick's court with the higher-level ninth circuit appeals court also based in San Francisco, Trump made clear he was ready to fight the decision.

"First the Ninth Circuit rules against the ban & now it hits again on sanctuary cities - both ridiculous rulings. See you in the Supreme Court!" Trump tweeted.

President Donald Trump's attempts to ban people from six Muslim countries from travelling to the United States "played into the hands" of extremists, the UK's former prime minister said Wednesday.

Trump has said a travel ban is needed to preserve national security and keep out extremists. But federal judges have halted Trump's revised executive order issued in March to temporarily close US borders to refugees and nationals from six Muslim-majority countries.

First Daughter Ivanka Trump is contradicting her father, the US president, insisting that allowing Syrian refugees to immigrate to the United States “has to be part of the discussion” over ending Syria’s years old civil war.

“I think there is a global humanitarian crisis that’s happening, and we have to come together, and we have to solve it,” she told NBC News in an interview aired Wednesday.

David Cameron condemned the Trump administration's proposed travel ban, saying it alienated Muslim moderates and allies, as senior figures from global tourism gathered in Bangkok for a conference. Cameron said in his opening speech that violent extremism was "the biggest threat to our world and also to this industry" but that leaders should not promote policies that emboldened extremists.  Earlier, a White House statement branded the ruling, a new setback to Trump's promised crackdown on illegal immigrants, as "a gift to the criminal gang and cartel element in our country, empowering human trafficking and sex trafficking."

It was the second major legal blow to Trump's pledge to sharply tighten government immigration policy.

In February, the Ninth Circuit ruled against the White House order to suspend immigration from seven mostly-Muslim countries as well as all refugees.

The court ruled that the order was in effect a ban on Muslims, violating the US constitution's guarantee of religious freedom.

Orrick also ruled that Trump's January 25 order to deny federal funds to sanctuary cities violated the Constitution.

"The Constitution vests the spending powers in Congress, not the president, so the order cannot constitutionally place new conditions on federal funds," he said.

"Federal funding that bears no meaningful relationship to immigration enforcement cannot be threatened merely because a jurisdiction chooses an immigration enforcement strategy of which the president disapproves," Orrick said.

His decision could affect more than 300 cities and counties that have denounced Trump's order.

But the White House said in a vitriolic statement late Tuesday, that "the rule of law suffered another blow, as an unelected judge unilaterally rewrote immigration policy".

It called Orrick's ruling, in a case that focused on San Francisco itself and Santa Clara County, home to Silicon Valley and San Jose, as "one more example of egregious overreach" by a single judge that "undermines faith in our legal system."

"San Francisco, and cities like it, are putting the well-being of criminal aliens before the safety of our citizens, and those city officials who authored these policies have the blood of dead Americans on their hands."

Orrick noted that the Justice department's lawyers weakly argued the case, implicitly recognizing that Trump did not have autocratic powers over disbursing federal funds to cities which often heavily depend on them for their budgets.

Trump's promise of appeal could land the case in the Ninth Circuit court, viewed as one of the more liberal venues in the federal court system and so a more risky court for the government to lodge a challenge.

The ruling did not end the government's battle against sanctuary cities and counties. Attorney general Jeff Sessions has repeatedly blasted those jurisdictions for not aiding in the government's promise to expel a large part of the 11.3 million undocumented immigrants in the country.

Mayors say the government is unreasonably demanding they divert public safety and law enforcement manpower to immigration roundups that often affect law-abiding people in the country for decades.

Orrick, however, also ruled in support of Sessions's narrower threat last week to withhold Justice department grant funds to cities that do not cooperate with the government's immigration crackdown.