Using php insertBefore inside for loop -


i working on adding amp-ad amp pages based on how many paragraphs in post. trying figure out why loop adding 1 item when suppose adding item every 10 paragraphs. post working on has 100+ paragraphs. not live yet need figuring out why not adding item every 10. here code:

$p_nodes = $body->getelementsbytagname( 'p' );     if ( $p_nodes->length > 10 ) {         for($i=10; $i <= $p_nodes->length; $i+=10) {             $p_nodes->item( $i )->parentnode->insertbefore( $ad_node, $p_nodes->item( $i ));         }     }else{         $p_nodes->item( 10 )->parentnode->insertbefore( $ad_node, $p_nodes->item( 10 ));     } 


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -