PHP code example of dneustadt / html-tag-replace

1. Go to this page and download the library: Download dneustadt/html-tag-replace library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dneustadt / html-tag-replace example snippets


$markup = '
    <img src="#" alt="foo">
    <img src="#">
    <div id="foo">bar</div>
    <em class="foo">bar</em>
    <input type="text" name="foo">
';
  
$replacer = new HtmlTagReplace($markup);
  
echo $replacer->replaceTag(
        'img',
        'a',
        false,
        ['src' => 'href', 'alt' => false],
        'title="show image"',
        'show image</a>'
    )->replaceTag(
        'div',
        'article',
        true,
        ['id' => 'class'],
        null,
        null,
        '<hr>'
    )->replaceTag(
        'em',
        'strong',
        true
    )->replaceTag(
        'input',
        'input',
        false,
        ['name' => ['name', 'id']]
    )->compress()->getMarkup();