A large voltage range can be accommodated by using Vin to drive a constant current source.
Voltages below the minimum forward voltage of the optocoupler's IR diode could be accommodated by using a boost converter to up-convert the lower voltages - but this is best avoided unless the very low voltages are essential.
Here is a conceptual circuit diagram - which would work as is in most cases.
Component values can be adjusted to suit.
Vin is taken to be 3V to "more".
How high "more" is depends on the power rating of R2 and the voltage rating of Q2 and R2.
When voltage is applied Q2 is turned on by R2.
Current in R1 rised until Q1 is turned on when R1 drops about .6V.
Q1 now clamps the base of Q2 at a level that maintains its turn on voltage.
Current drawn I= V/R = 0.6V/R1 , which here =
0.6/100 = 6 mA (approximately).
This current can be changed by changing R1 to suit the optocoupler requirements.
Lower optocoupler currents ease the dissipation requirements discussed below.
Deep-ending on your source a low Iin may be essential.
At 3V in, V_Q2_b = Vb1_Q1 + Vbe_Q2 ~= 1.2V.
So V across R2 ~= 3Vin - 1.2V = 1.8V.
Ib_Q2 = Vr2/R2 = 1.8/10000 ~= 0.02 mA
To support the required 6 mA in this case Beta_Q2 must be IC_Q2/Ib_Q2
= 6 mA / 0.02 mA = 300.
R2 can be made smaller to increase I_R2 and so reduce the required beta of Q2.
I specified a BC337-40 for Q2 as they are low cost, widely available and have guaranteed beta of 250 - 630 and typically 400.
At Vin of 3V operation is marginal at beta = 250 and reducing R to say 6k* would be wise.
BC337 data sheet.
The BC337 is rated at Vceo of 50V so is marginal at 50V (but probably OK - but ...). A surface mount version with identical specifications is available (except for dissipation).

simulate this circuit – Schematic created using CircuitLab
At Vin = 50V, dissipation in R2 = V^2/R = 2500/10k = 1/4 W.
Using at least a 0.5W part is indicated and 1W "won't hurt".
If R2 is reduced power consumption should be checked.
Q2 max dissipation ~= Iopto x Von = 6 mA x 50C = 300 mW.
C337 TO92 package has a thermal resistance Rtja = 200 C/w.
At 300 mW temperature rise is 200 x 0.3 60C which is "not nice" but OK.
If you really want good operation across the maximum possible range something like the (almost magical) Diodes Inc ZXTN25100DG at under $US1 in 1''s ex Digikey, will do the job with ease. This is in a SOT223 surface mount package but is easily used on strip board or as a through hole part with mounting pins.
Beta, dissipation and operating voltage are higher than for the BC337. What's not to like - apart from the still reasonable price?
Also look at the SMD only SOT23 insanely high dissipation rating ZXTN25100DFH - but the ZXTN25100DG is much nicer to use.