Search code examples
phphtml-content-extraction

Identify if html contains template language code while extracting from URL


I am trying to fetch plain text content from any provided URL which has some text data. While testing the feature on one of the URLs I found some template language code present in the source.

{{if user.username || user.id}}
                {{:user.name}}

Any idea how can I clean this code from my output html? Is it possible to achieve something like this using PHP?


Solution

  • You can use something like this:

    $filtered_string = preg_replace('/' . preg_quote('{{') .
        '.*?' .
        preg_quote('}}') . '/', '', $str);
    

    Here $str would be your input html