<input name="ti01tle" type="text" id="title" value="" class="txt" title="标题最多为60个字符" /><input name="title100" type="text" id="title" size="60" title="标题最多为60个字符" /><input name="tbbitle" type="text" class="colorblue" οnfοcus="this.className='colorfocus';" οnblur="this.className='colorblue';" id="title" size="60" title="标题最多为60个字符" />一个论坛的标题输入筐 name="xxxx",做了一些变化。不是简单的name="title", 而是name="a123title" 等等,但是id="title"是不变的。我要抓取红色部分,怎样用一个正则表达式匹配出来?
foolbirdflyfirst(龙腾虎跃)
$html = <<< html < input name = " ti01tle " type = " text " id = " title " value = "" class = " txt " title = " 标题最多为60个字符 " /> < input name = " title100 " type = " text " id = " title " size = " 60 " title = " 标题最多为60个字符 " /> < input name = " tbbitle2 " type = " text " class = " colorblue " onfocus = " this.className='colorfocus'; " onblur = " this.className='colorblue'; " id = " title " size = " 60 " title = " 标题最多为60个字符 " /> < input id = " title " name = " tbbitle " type = " text " class = " colorblue " onfocus = " this.className='colorfocus'; " onblur = " this.className='colorblue'; " size = " 60 " title = " 标题最多为60个字符 " /> < input id = " title4 " name = " tbbitle " type = " text " class = " colorblue " onfocus = " this.className='colorfocus'; " onblur = " this.className='colorblue'; " size = " 60 " title = " 标题最多为60个字符 " /> html; $reg = ' #<input/s+(?:(?=id/="title")[^>]*name="([a-z0-9]*)"[^>]*)|(?:[^>]*name="([a-z0-9]*)"[^>]*(?=id/="title")[^>]*)/>#is ' ; preg_match_all ( $reg , $html , $mat ); echo " <pre/> " ; print_r ( $mat [ 1 ]); // id="title"出现在name=".."之前 print_r ( $mat [ 2 ]); // id="title"出现在name=".."之后