Trying to understand how this PNP works
When the opto is off, the base of the PNP is in series with the 10k resistor. I guess that the voltage on the base would be lower then the source voltage as the resistor will have a voltage drop.

The idea is that the resistor pulls the base up to the emitter's voltage to prevent it turning on due to leakage current. The 10k &quot;bleeds away&quot; any leakage current.

If I understand correctly, the PNP will be on if the base has 0.7 V less then the voltage on the emitter.

Correct.

But when the opto is on, then the base is in a voltage divider (in between the 10k and the 1k resistors) so then again, the voltage on the base should be less then the one on the emitter.

That's correct and the base-emitter junction voltage will be about 0.7 V. (It behaves like a diode.)

How can this PNP be turned off?

Easy. Turn off the opto-isolator. Now no current will flow through the 1k resistor, the 10k resistor will pull the base up to the emitter's voltage, the base will not be forward biased and the transistor will turn off.


Could you try explaining the « the resistor pulls the base up to the emitter's voltage » in other words.

Due to thermal effects the transistor will leak a little current between the emitter and the collector. This means it is not fully &quot;off&quot;. By connecting the base to the emitter we can stop this - but then we would need another switch in that connection to allow the transistor to work normally. Instead we connect the base to the emitter with a resistor. The resistor is a high enough value not to affect the rest of the circuit (your 1k is much stronger due to its low resistance) but it's low enough that any charge on the base is bled back to the positive supply and the transistor is turned fully off.
This might be easier to understand for the NPN case because we are more used to referencing everything from the ground rail.
For a specification, have a look at page 2 of the 2N2222 datasheet. You'll see the current is tiny, even at 50 V VCB.