<?php $res = '... Set-Cookie: bb_test=1835118987; ... '; preg_match('#bb_test=([^;]*)#', $res, $match_session); echo $match_session[1]; ?>