Is getting admission as a foreigner to a PhD program through a position within a research project of a principal investigator mostly hopeless? There are generally two kinds of ways to get admitted to a PhD program in Europe or some other places—one is through a calling for PhD applications by a research institute, a university department or a research division therein consisting of researchers involved with closely related research topics, and another is through an opening of a position—which can be called PhD position, PhD scholarship, research assistant, or research associate as far as I have seen—within a research project of a principal investigator. The first usually administers once every a fixed short period, like a year, half a year or four months, usually has multiple positions and is flexible in research topics for PhD studies while the second only administers when an principal investigator gets the funding, usually only has one position each opening though it can occasionally have two, and the PhD research topic is confined to that project.

I have long heard that if one wants to pursue a PhD in Holland, they have to first look for a related job vacancy. I guess this means Holland mainly admits PhD students by the second way mentioned above. However, I also heard from activities regarding Studying in Holland in my country that it's almost impossible for a foreigner to win a PhD position through a job vacancy in Holland unless they have a network with related principal investigators in Holland, like they have pursued their MSc in Holland. I wonder whether this also applies to other countries, particularly in Europe, where a PhD position opening within a research project like a job vacancy, that is my aforementioned second way of admission, seems very common as a whole. I heard the reason that Holland rarely awards job-like PhD positions to networkless foreigners is that they don't have many vacancies of that sort and therefore they prioritize their compatriots. I wonder whether this is the same situation for other countries.
Most PhDs in the bio-molecular subjects in the UK are awarded through the "job-like" route (although that is changing in some places). For most of these the position will only be open to those that count as "Home" students. Until we leave the EU in October, that includes people from the UK or the EU (after that it will just be people from the EU).

The reason for this has nothing to do with already being part of a network etc, but simply because these positions might look like jobs, but they are not. They are usually government funded PhD scholarships (where the PI has been selected to stand proxy for the government in selecting the student). For better or worst (worst in my opinion) the government has decided that its job is to educate native students (and is forced to include European students by the EU). 

However, such studentships will almost always state in the advert "Home/EU applicants only".