php - How can I specify "any character" including double quotes, gt, lt, equal -


in php have next text:

$text='<div id="my_date_div"                             year="2010"                             month="12"                             day="07"                             hour="00"                             minute="00"                         >                   <span id="my_span_days">dys</span>                             <span id="my_span_hours">hrs</span>                                                  </div>' 

i perform preg_replace() keep values of upper text, example year (2010) , hour(00).

i perform lookup /year=\"/ , /hour=\"/, dont know how remove other text dont want since expresion [.+\s+]* not match characters " or <

what have is

$regex = "/[.+\s+]*year=\"(\d+)\"[.+\s+]*hour=\"(\d+)\"[.+\s+]*$/"; $regrep = "$1 $2"; echo preg_replace($regex, $regrep, $text); 

any hint? thanks

you can use preg_match_all match text want , replace input string matched part:

preg_match_all('/((?:year|hour)\s*=\s*"\d+")/m',$text,$m); $text = implode("\n",$m[1]); 

ideone link


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -