wordpress - different excerpt in php -


hi how excerpt code using php ?

it's wordpress content . there not way in wordpress

from

<div class='first'>first</div> <div class='second'>second</div> <div class='first'>first</div> <div class='second'>second</div> <div class='first'>first</div> <div class='second'>second</div> . . . 

to

<div class='first'>first</div> <div class='second'>second</div> 

you can try using preg_replace_callback:

//if html retrieved in variable $html, $html = "<div class='first'>first</div> <div class='second'>second</div> <div class='first'>first</div> <div class='second'>second</div> <div class='first'>first</div> <div class='second'>second</div>";   $validate = array('first'=>true,'second'=>true); $response = trim(preg_replace_callback('/<div\s?.*\/div>/',function($match)use(&$validate){     reset($validate);$key = key($validate);     if(strstr($match[0],$key) != false && $validate[$key] == true){         $validate[$key] = false;         return $match[0];     }     next($validate);$key = key($validate);     if(strstr($match[0],$key) != false && $validate[$key] == true){         $validate[$key] = false;         return $match[0];     } },$html)); var_dump($response); 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -