New York Stock Exchange
Specialist trader Geoffrey Friedman (L) gives a price just after the opening bell on the floor of the New York Stock Exchange July 21, 2014.Reuters

Stocks ended mostly higher on Wednesday, with the S&P 500 closing at a record on Apple's bullish results, though Boeing weighed on the Dow and conflicts in Ukraine and the Gaza Strip kept the broader market's gains in check.

Biotech stocks ranked among the day's biggest gainers, boosted by some strong results and drug trial data. The Nasdaq Biotech index jumped 2.2 percent in its fourth straight day of gains.

Apple Inc gave one of the biggest lifts to the market, rising 2.6 percent to $97.19 as concerns faded about the iPhone maker's margins. Dow component Microsoft Corp rose 0.1 percent to $44.87 after the company said it aimed to get its money-losing Nokia phone unit to break even within two years.

"Earnings season has been going very well, beating on both the top and bottom line, which suggests companies will continue to execute well," said Alan Gayle, senior investment strategist at RidgeWorth Investments in Atlanta.

Among the companies that reported results after the market closed, Facebook Inc posted stronger-than-expected revenue growth and its stock climbed 3.5 percent to $73.80 in extended-hours trading. TripAdvisor Inc shares tumbled 9.4 percent to $97.25 in after-hours trading after the travel website company reported earnings that missed expectations.

The shares of Dow component AT&T Inc shares slipped 1.4 percent to $35.38 in extended-hours trading after the No. 2 U.S. mobile provider reported revenue that missed analysts' forecasts.

About 68.5 percent of the S&P 500 components have reported earnings above expectations, topping the long-term average of 63 percent, according to Thomson Reuters data. On the revenue side, 63.1 percent have beaten forecasts, above the historical average of 61 percent.

Overseas issues continued to limit the market's gains. Two Ukrainian fighter jets were downed near the area where a Malaysian Airlines passenger jet was shot down last week, a spokesman for Ukraine's military operations said Wednesday.

Violence also continued in the Gaza Strip, though U.S. Secretary of State John Kerry said indirect truce talks between Israel and Hamas had made some progress.

"There's a battle going on in the market between earnings and geopolitical issues, and right now, it looks like earnings have a slight edge," said Gayle, who helps oversee $50 billion in assets. "These are big areas of concern, but they've yet to translate to anything tangible from an economic standpoint."

The Dow Jones industrial average fell 26.91 points or 0.16 percent, to end at 17,086.63. The S&P 500 gained 3.48 points or 0.18 percent, to close at 1,987.01, surpassing the record set on July 3. The Nasdaq Composite .IXIC added 17.68 points or 0.4 percent, to 4,473.70.

While the S&P 500 ended at a record close, the Dow was kept under pressure by Boeing Co, which fell 2.3 percent to $126.71. The U.S. aircraft maker reported a 52 percent jump in quarterly profit, but investors were spooked by rising costs in its military tanker program.

PepsiCo rose 1.9 percent to $90.82 after the soft drinks and snacks company reported a higher-than-expected quarterly profit and raised its full-year adjusted earnings forecast.

In the biotech space, Biogen Idec reported sharply higher-than-expected quarterly revenue on surging sales of its new treatment for multiple sclerosis and raised its full-year profit forecast. Its stock shot up 11.2 percent to $337.60.

Intuitive Surgical rose 17.7 percent to $461.63 and was the S&P 500's biggest percentage gainer a day after the company, which makes the da Vinci robot surgical system, reported second-quarter revenue that beat expectations.

Puma Biotechnology nearly quadrupled, up 295.4 percent to $233.43 on heavy volume a day after the company said its experimental breast cancer drug met its main goal in a late-stage trial.

About 55 percent of stocks traded on the New York Stock Exchange closed higher while 47 percent of Nasdaq-listed shares ended in positive territory.

About 5.33 billion shares traded on all U.S. platforms, according to BATS exchange data, compared with the month-to-date average of 5.55 billion.