Skip to content

Instantly share code, notes, and snippets.

@mdjwel
Created April 5, 2019 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdjwel/e6cc900038c679be3cab9ac6355bee20 to your computer and use it in GitHub Desktop.
Save mdjwel/e6cc900038c679be3cab9ac6355bee20 to your computer and use it in GitHub Desktop.
Here, I'm listing some functions that do string manipulation in WordPress.
<?php
/**
* Get a specific html tag from content
* @return a specific HTML tag from the loaded content
*/
function rogan_get_html_tag( $tag = 'blockquote', $content = '' ) {
$dom = new DOMDocument();
$dom->loadHTML($content);
$divs = $dom->getElementsByTagName( $tag );
$i = 0;
foreach ($divs as $div) {
if($i == 1) {
break;
}
echo "<{$div->tagName}> {$div->nodeValue} </{$div->tagName}>";
++$i;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment