Emulate jQuery's clone() in PHP -



Emulate jQuery's clone() in PHP -

hi guys 1st time here have spent many hours find out how can it.

jquery clone can me downside can not utilize seo purpose s.

so want alternative using php re-create text within tag , echo anywhere.

<div class="content-to-copy" id="content-to-copy">copy text</div> <div class="content-new-location" class="content-new-location"></div>

i can acheive above using jquery clone using codes below

jquery clone code pen

how can using php?

alternatively, (simple html dom parser actually), utilize domdocument in conjunction domxpath on one. consider example:

$original_html = '<div class="content-to-copy" id="content-to-copy">copy text</div><div id="content-new-location" class="content-new-location"></div>'; $dom = new domdocument; @$dom->loadhtml($original_html); $xpath = new domxpath($dom); // clone $clone = $xpath->query('//div[@id="content-to-copy"]//text()'); $clone_value = (string) $clone->item(0)->nodevalue; $xpath->query('//div[@id="content-new-location"]')->item(0)->nodevalue = $clone_value; // styling see difference $xpath->query('//div[@id="content-new-location"]')->item(0)->setattribute('style', 'color: red; font-weight: bold;'); $final_html = $dom->savehtml($dom); echo $final_html;

sample output

php jquery clone

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -