<?php    /* --- ۞---> text { encoding:utf-8;bom:no;linebreaks:unix;tabs:4sp; } */
                                                      
$tagtools_version '0.5';
/*
    Tag-Tools
    from corz.org

    A few handy tag-stripiping and converting tools.
    Mostly just added quickly, as and when I neeed them.

    So far..

    convert html to php ('' single quoted echo)
    convert html to php echo ("" double quotes)
    convert php to html (php '' single quoted echo)
    convert php to html ("" double quoted echo)
    convert php "" (double) echo to '' (single) echo
    strip html tags completely
    encode text to html ascii entities
    encode text to html entities
    URL and Raw URL encoding

    ;o) Cor

    (c) 2003->tomorrow! cor + corz.org ;o)

    Please view the license for this free software, here..
    http://corz.org/public/docs/license/free-scripts-licence.php

*/

// You will need a local copy of this for IE7/8 users..

if (!empty($_POST['cvt_area'])) {

    
$text = ($_POST['cvt_area']);
    
$text stripslashes($text);

    
// encourage folk to enable themselves..
    
if (strlen($_POST['cvt_area']) > 1048576) {    // 1MB
        
$converted '

BANDWIDTH ABUSE!

Please download the source and use this tool on your OWN server!'
;
    } else {

        if (isset(
$_POST['php2html'])) {
            
$converted php2html($text);
        }
        elseif (isset(
$_POST['php2html2'])) {
            
$converted php2html2($text);
        }
        elseif (isset(
$_POST['html2php'])) {
            
$converted html2php($text);
        }
        elseif (isset(
$_POST['html2php2'])) {
            
$converted html2php2($text);
        }
        elseif (isset(
$_POST['striphtml'])) {
            
$converted striphtml($text);
        }
        elseif (isset(
$_POST['encode'])) {
            
$converted switch_entities(encode($text));
            
//$converted = htmlentities(encode($text), ENT_SUBSTITUTE);
        
}
        elseif (isset(
$_POST['entities'])) {
            
$converted utf8_decode($text);
            
//$converted = htmlentities($converted, ENT_SUBSTITUTE);
            
$converted switch_entities($converted);
            
$converted htmlspecialchars($converted);
        }
        elseif (isset(
$_POST['urlencode'])) {
            
$converted urlencode($text);
        }
        elseif (isset(
$_POST['rawurlencode'])) {
            
$converted rawurlencode($text);
        }
        elseif (isset(
$_POST['php2php'])) {
            
$converted php2php($text);
        } else { 
$converted ''; }

    }

 } else {
    
$text '';
    
$converted '';
 }

// header. make it your own, keep it at home!
do_header(); // scroll down for the header code itself.
@include $_SERVER['DOCUMENT_ROOT'].'/inc/header.php'// include your header here, maybe.

echo '

<form method="post" action="'
,$_SERVER['REQUEST_URI'],'">
<div class="content tool">

    <label><span class="big"><strong>php &amp; html tag tools..</strong></span>
    not perfect by any means, but a real handy converter tool nonetheless..

    <textarea name="cvt_area" rows="21" cols="80" style="font:11px courier; width: 100%">'
,$converted,'</textarea>
    </label>

    <h3 class="centered"><a href="http://corz.org/engine?section=php"
    title="download the source! use your own effin bandwidth!">source is available!</a>
    you can run this at home!</h3>
    <br />


    <div class="butts" id="left-buttons">
        <span class="hoverme">
            <input type="submit" name="html2php2" value="do it!" />
            <span class="func-info">Convert html to php (\'\' single quoted echo)</span>
        </span><br />

        <span class="hoverme">
            <input type="submit" name="php2html2" value="do it!" />
            <span class="func-info">Convert php to html (\'\' single quoted echo)</span>
        </span><br />

        <span class="hoverme">
            <input type="submit" name="html2php" value="do it!" />
            <span class="func-info">Convert html to php echo ("" double quoted echo)</span>
        </span><br />

        <span class="hoverme">
            <input type="submit" name="php2html" value="do it!" />
            <span class="func-info">Convert php echo to html ("" double quoted echo)</span>
        </span><br />

        <span class="hoverme">
            <input type="submit" name="php2php" value="do it!" style="small"/>
            <span class="func-info">Convert php "" (double) echo to \'\' (single) echo</span>
        </span><br />
    </div>


    <div class="butts" id="right-buttons">'
;
    
/*
        <span class="hoverme">
            <input type="submit" name="striphtml" value="do it!" />
            <span class="func-info">Strip html tags completely</span>
        </span><br />
    */

echo '
        <span class="hoverme">
            <input type="submit" name="encode" value="do it!" />
            <span class="func-info">Encode to html ascii entities</span>
        </span><br />
        <span class="hoverme">
            <input type="submit" name="entities" value="do it!" />
            <span class="func-info">Encode to html entities</span>
        </span><br />
        <span class="hoverme">
            <input type="submit" name="urlencode" value="do it!" />
            <span class="func-info">URL encode text</span>
        </span>
        <br />
        <span class="hoverme">
            <input type="submit" name="rawurlencode" value="do it!" />
            <span class="func-info">Raw URL encode text</span>
        </span><br />
    </div>

<div class="clear-small"></div>
</div>
</form>'
;

@include 
$_SERVER['DOCUMENT_ROOT'].'/inc/footer.php';

echo 
'
</body>
</html>'
;

// convert html to php echo
function html2php($html){
    
$html=str_replace("\r","",$html);
    
$html=str_replace("\"","\\\"",$html);
    
$html=htmlspecialchars($html);
    
$returnHtml="echo\"";
    
$returnHtml.=$html."\";\n";
return 
$returnHtml;
}

// convert html to php echo '' - single quotes
function html2php2($html){
    
$html=str_replace("\r","",$html);
    
$html=str_replace("'","\'",$html);
    
$html=htmlspecialchars($html);
    
$returnHtml="echo '";
    
$returnHtml.=$html."';\n";
return 
$returnHtml;
}

// convert php echo to html
function php2html($html){
    
$html=stripslashes($html);
    
$html=str_replace("\";","",$html);
    
$html=str_replace("echo\"","",$html);
    
$html=str_replace("echo \"","",$html);
    
$html=stripslashes($html);
    
$html=htmlspecialchars($html);
    return 
$html;
}

// convert php echo to html '' - single quotes
function php2html2($html){
    
$html=stripslashes($html);
    
$html=str_replace("';","",$html);
    
$html=str_replace("echo'","",$html);
    
$html=str_replace("echo '","",$html);
    
$html=stripslashes($html);
    
$html=htmlspecialchars($html);
    return 
$html;
}

// convert php "" echo to php '' - double quotes single quotes. ahh.. much better
function php2php($html){
//    $html=stripslashes($html);
    
$html=str_replace('\\"','∆√∆',$html);
    
$html=str_replace('\'','\\\'',$html);
    
$html=str_replace('"','\'',$html);
    
$html=str_replace('∆√∆','"',$html);
    
$html=htmlspecialchars($html);
    return 
$html;
}

// we've all seen this code..
function striphtml ($text) {
/*
    $search = array ("'<script[^>]*?>.*?</script>'si",  // Strip out javascript
                     "'<[\/\!]*?[^<>]*?>'si",           // Strip out HTML tags
                     "'([\r\n])[\s]+'",                 // Strip out white space
                     "'&(quot|#34);'i",                 // Replace HTML entities
                     "'&(amp|#38);'i",
                     "'&(lt|#60);'i",
                     "'&(gt|#62);'i",
                     "'&(nbsp|#160);'i",
                     "'&(iexcl|#161);'i",
                     "'&(cent|#162);'i",
                     "'&(pound|#163);'i",
                     "'&(copy|#169);'i",
                     "'&#(\d+);'e");                    // evaluate as php

    $replace = array ("",
                      "",
                      "\\1",
                      "\"",
                      "&",
                      "<",
                      ">",
                      " ",
                      chr(161),
                      chr(162),
                      chr(163),
                      chr(169),
                      "chr(\\1)");

//     $text = preg_replace($search, $replace, $text);
    $text = preg_replace_callback($search, function($match) { return $replace; }, $format);
*/
    
return $text;
}

function 
encode($string) {

    for (
$i=0;$i<strlen($string);$i++) { $letters[] = $string[$i]; }
    while (list(
$key$val) = each($letters)) {
        
$letters[$key] = '&#'.ord($letters[$key]).';';
    }

return 
implode(''$letters);
}
/*    end function encode()
*/

function do_header() {
    global 
$tagtools_version;
    echo 
'<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
<title>convert html to php and php to html and more! ..\'tag tools\'.. from corz.org v'
,$tagtools_version,'</title>
<meta name="description" content="tag tools, convert html to php tags, strip html, convert html to php, convert single quotes, convert double quotes,encode html entities, tag stripping, URL encoding and more!" />
<link rel="stylesheet" href="/inc/css/tech.css" type="text/css" media="screen" />
<style media="screen">
/*<![CDATA[*/
.form {
    margin-top: 9rem;
    margin-bottom: 0;
    float: none;
    clear: both;
}
.butts {
    font-size: 0.75em;
    text-align: justify;
}
#left-buttons {
    width: 49%;
    float: left;
}
#right-buttons {
    width: 40%;
    float: right;
}

.func-info {
    padding-left: .5rem;
}
.hoverme:hover {
    background: #FFFF00;
}
input {
    margin-bottom: .5rem;
}


@media screen and (max-width: 800px) {
    #left-buttons, #right-buttons {
        width: 100%;
        float: none;
        text-align: center;
    }
    #left-buttons input, #right-buttons input {
        margin-bottom: 2rem;
    }
}


/*]]>*/
</style>
</head>
<body>
<div class="toplinks">
    <a href="http://corz.org/source/php/" onclick="window.open(this.href); return false;"
    title="Another Web Site Spare Part.. from corz.org">more like this</a>
</div>'
;
}


// damn php 5.3!
function switch_entities($string) {
    if (!
defined('PHP_VERSION_ID')) {
        
$version explode('.'PHP_VERSION);
        
define('PHP_VERSION_ID', ($version[0] * 10000 $version[1] * 100 $version[2]));
    }
    if (
PHP_VERSION_ID >= 50390) {
        return 
htmlentities($stringENT_SUBSTITUTE);
    } else {
        return 
htmlentities($string);
    }
}



/*

version history:

    0.5
    Remove IE9 compatability. Suck it up.

    0.4
    Improved HTML entity encoding for php 5.4+ (falls-back when not available)

    0.3.3
    Aha! That's why I couldn't get the hovers to work! I'd used
    a dot, instead of a colon. Much better now.

    0.3.1
    fixed wee bug in the input button for html>php (single quotes)
    (thanks Jean!)

    0.3
    brings us xhtml compliance and URL encoding, also mousover
    highlighting to help navigation. have fun!

    0.2
    added entity encoding.

    0.1
    first tag tools. convert php to html and back, and strip tags

*/
?>
back to the source menu
downloadtest

Welcome to corz.org!

Bugs? What bugs? Juggling two energetic boys (of very different ages) on Coronavirus lockdown, I'm unlikely to have them all fixed any time soon. Mail me! to prioritise!