<?php $str = "<div><span><a href=\"foo\">foo<a></span></div>"; $reg = "/href=('|\").*('|\")/i"; preg_match($reg, $str, $m); echo str_replace('href=','',str_replace('"','',$m[0])); ?>