Skip to content

Instantly share code, notes, and snippets.

@odan
Created July 4, 2019 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save odan/9f764a941c1485a4500340b3bcb0a83b to your computer and use it in GitHub Desktop.
Save odan/9f764a941c1485a4500340b3bcb0a83b to your computer and use it in GitHub Desktop.

Remove HTML tags

<?php

$html = '<div class="cc">
    Explore the use of simple 
    <a class="keyword_w_elaboration">technologies</a>
    <div class="elaboration" style="text-decoration:none">
        <div class="elaboration_controls"></div>
        <div class="elaboration_content">
            <div class="keyword_elaboration_title">technologies</div>
            things that extend human abilities (e.g., axe)  &nbsp;
        </div>
    </div> 
    to extend their abilities
</div>';

$text = strip_tags($html);
$text = html_entity_decode($text);
$text = trim(str_replace("\xc2\xa0", ' ', $text));
$text = preg_replace('/(\s\s+|\n|\t)/', ' ', $text);

echo $text;

Output

Explore the use of simple technologies technologies things that extend human abilities (e.g., axe) to extend their abilities

Demo: https://3v4l.org/1ZdRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment