The date-manipulating capabilities of mktime(), combined with date("w", ... ) which gives you the day-of-week number, are the tools you need.
Off the top of my head, I'd do it like this:
<ol>
<li>Create (via mktime) a date representing the 1st of the target month.
<li>Find the difference, in days, between the desired day-of-week and
the day-of-week of the first of the month. (Ignore the week # for now;
also, this has to be mod-7 arithmetic as the result can never be negative.)
<li>To this difference, add (weekno - 1) * 7; this will give you a number
of days to add to the first of the month. Use this value in another
mktime() call to generate the desired date.
</ol>
If there's any possibility of asking for the 5th weekday of the month,
be sure to capture the resulting month from the return value of the
last mktime() because most of the time there won't be such a date
and you can tell this because the month will roll over.