Online Text Tools Template
<?php
/*
Template Name: Online Text Tools Template
*/
get_header();
$tools = [
'count_characters' => ['Count Characters', '#ff7675'],
'count_words' => ['Count Words', '#74b9ff'],
'count_paragraphs' => ['Count Paragraphs', '#55efc4'],
'uppercase_text' => ['Uppercase Text', '#fdcb6e'],
'lowercase_text' => ['Lowercase Text', '#a29bfe'],
'capitalize_text' => ['Capitalize Text', '#00cec9'],
'reverse_text' => ['Reverse Text', '#00b894'],
'remove_whitespace' => ['Remove Whitespace', '#6c5ce7'],
'extract_urls' => ['Extract URLs', '#ffeaa7'],
'count_lines' => ['Count Lines', '#0984e3'],
'shuffle_text' => ['Shuffle Text', '#fab1a0'],
'remove_html_tags' => ['Remove HTML Tags', '#ff6b6b'],
'add_dash_with_words' => ['Add Dash with Words', '#d63031'],
// Add more text tools here
];
$results = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$selectedTools = isset($_POST['tools']) ? $_POST['tools'] : [];
foreach ($selectedTools as $tool) {
if (array_key_exists($tool, $tools)) {
$functionName = 'text_tool_' . $tool;
if (function_exists($functionName)) {
$results[$tool] = $functionName($_POST['text']);
}
}
}
}
function text_tool_count_characters($text) {
return strlen($text);
}
function text_tool_count_words($text) {
$words = explode(' ', $text);
$words = array_filter($words, function($word) {
return !empty(trim($word));
});
return count($words);
}
function text_tool_count_paragraphs($text) {
$paragraphs = preg_split('/\r\n|\r|\n/', $text);
$paragraphs = array_filter($paragraphs, function($paragraph) {
return !empty(trim($paragraph));
});
return count($paragraphs);
}
function text_tool_uppercase_text($text) {
return strtoupper($text);
}
function text_tool_lowercase_text($text) {
return strtolower($text);
}
function text_tool_capitalize_text($text) {
return ucwords($text);
}
function text_tool_reverse_text($text) {
return strrev($text);
}
function text_tool_remove_whitespace($text) {
return preg_replace('/\s+/', '', $text);
}
function text_tool_extract_urls($text) {
$urls = [];
$pattern = '/\b(?:https?|ftp):\/\/\S+\b/i';
preg_match_all($pattern, $text, $matches);
foreach ($matches[0] as $match) {
$urls[] = $match;
}
return implode("\n", $urls);
}
function text_tool_count_lines($text) {
$lines = explode("\n", $text);
return count($lines);
}
function text_tool_shuffle_text($text) {
$characters = str_split($text);
shuffle($characters);
return implode('', $characters);
}
function text_tool_remove_html_tags($text) {
return strip_tags($text);
}
function text_tool_add_dash_with_words($text) {
$words = explode(' ', $text);
$words = array_filter($words, function($word) {
return !empty(trim($word));
});
return implode('-', $words);
}
// Add more text tool functions here
?>
<style>
.text-tools-container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f8f8f8;
}
.text-tools-container h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.text-tools-container form {
display: flex;
flex-direction: column;
align-items: center;
}
.text-tools-container textarea {
width: 100%;
height: 150px;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
resize: vertical;
}
.text-tools-container .text-tools {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 10px;
margin-bottom: 10px;
}
.text-tools-container .text-tool {
position: relative;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
transition: all 0.3s ease;
perspective: 1000px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.text-tools-container .text-tool:hover {
transform: translateY(-5px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}
.text-tools-container .text-tool label {
display: block;
font-weight: bold;
color: #333;
margin-bottom: 5px;
}
.text-tools-container input[type="submit"] {
width: 150px;
padding: 10px;
background-color: #4caf50;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
font-weight: bold;
transition: background-color 0.3s ease;
}
.text-tools-container input[type="submit"]:hover {
background-color: #45a049;
}
.text-tools-container .results {
margin-top: 20px;
}
.text-tools-container .result-item {
margin-bottom: 10px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #fff;
}
.text-tools-container .result-item h4 {
margin-bottom: 5px;
color: #333;
}
.text-tools-container .result-item p {
white-space: pre-line;
color: #555;
}
<?php foreach ($tools as $tool => $toolData) : ?>
.text-tools-container #tool-<?php echo $tool; ?> .text-tool {
background-color: <?php echo $toolData[1]; ?>;
}
<?php endforeach; ?>
</style>
<div class="text-tools-container">
<h2>Online Text Tools</h2>
<form method="POST">
<textarea name="text" rows="5" placeholder="Enter text..." required></textarea>
<div class="text-tools">
<?php foreach ($tools as $tool => $toolData) : ?>
<div class="text-tool" id="tool-<?php echo $tool; ?>">
<input type="checkbox" name="tools[]" value="<?php echo $tool; ?>">
<label for="<?php echo $tool; ?>"><?php echo $toolData[0]; ?></label>
</div>
<?php endforeach; ?>
</div>
<input type="submit" value="Submit">
</form>
<div class="results">
<?php foreach ($results as $tool => $result) : ?>
<div class="result-item">
<h4><?php echo $tools[$tool][0]; ?></h4>
<p><?php echo $result; ?></p>
</div>
<?php endforeach; ?>
</div>
</div>
<?php get_footer(); ?>
Post a Comment