How do I counter Phantom Lancer?
Earthshaker. When their team is maxing the number of units in a small area, get Earthshaker going with a blink. His ultimate does bonus damage based on enemy units within a radius, so wait until the Phantom Lancer is there with a creep wave and his team and you'll see health bars melt.
To avoid repeating other answers: if you can't change your pick against him (Captains Draft, last minute PL, whatever), changing your itemization can help. Ghost Scepter, as a poor support, or an earlier BKB, as a more farmed role, can do wonders against PL's swarm in the mid/late-game.
You can potentially turn the tide of any fight if you don't die for a precious extra couple seconds: of not losing all your health (ghost scepter), or 5+ seconds not losing all of your mana (BKB; you don't know how much you like your mana pool as a carry until it's gone!).
Other items are, as always, situational. You can't pick, say, KotL, and skip a necessary Mekansm for Eul's and Ghost Scepter and expect to be as helpful. Eul's Scepter provides a similar escape, much more so when paired with a blink dagger. Agh's or Refresher might be helpful per hero. Force Staff on a 3-5 role is almost always a good idea already, but unless you're doing some coordinated plays staffing allies over a cliff to save them from PL, it might not have the escapism effect you want with PLs passive chasing ability.
More expensive items that could help include Shiva's, Battlefury (on Ember Spirit in particular; stack them), Mjollnir (much more so than a casual Maelstrom), and Crimson Guard.
Misc. items of note: Dust of Appearance, similar to Bounty Hunter's Track or Slardar's ultimate, will persist on the "real" PL after he uses his second ability. This, or hero abilities like those, can move your itemization options to single target lockdown actives, including Abyssal Blade, Orchid, and Sheepstick. But finding the real PL in a fast paced skirmish is hard to coordinate consistently, so as always, situational pickups.
Note: PL isn't generally an issue in the very early stages of the game; depending on his itemization, a good Jakiro combo can nullify a horde of illusions. Later in the game, when PL is a higher level and has tankier illusions, not many heroes have abilities that scale for these illusions en masse. Lion and Disruptor, for example, can knock out any single illusion easily, and Jakiro can deal with early level illusions well, but for the real issue, a horde of farmed PL illusions, a diffusal blade charge, or a dual breath isn't going to help. My suggestions are more geared toward that ominous mid lane push from a team with a farmed PL.
Phantom Lancer is a really weak starting hero. With low damage, low health and low mana, and without any CC or disable, he can be shut down quite easily at early game through constant ganking.
1. Gyrocopter
Most likely, he will pick mid lane for ganking. He will harrass Phantom Lancer constantly using his homing missile, and his ultimate, Call Down, is a huge AOE nuke, instantly killing or nearly killing all of Phantom Lancer's illusion.
2. Lion
He has 2 skills - Mana Drain and Hex - that kills illusions instantly or after 0.25 second delay. Lion can basically destroy Phantom Lancer's illusion, making his main skills, Doppelwalk and Juxtapose useless.
3. Medusa
Medusa's ultimate, Stone Gaze, instantly kills illusion, and have Phantom Lancer's attack speed slowed, movement speed slowed, and have a chance of being stunned and taking bonus physical damage.
4. Pugna
His ultimate, Life Drain, instantly kills illusions and drains Phantom Lancer's HP. Nothing much to say here.
5. Disrupter
His W, Glimpse, will instantly kill illusions.
6. Diffusial Blade
Purging will instantly kill all illusions.
Hope I helped :)