code:php:qgen
QGen
A simple, no-frills quote generator written in PHP.
Features
- Puts square brackets plus space (
>
) before each line of a text. - Copies the modified text to your clipboard. The jQuery code required for this is delivered via Google CDN. Feel free to host the code on your own server for privacy reasons.
- No CSS, just old school HTML. 😎
Source Code
- qgen.php
<!DOCTYPE html> <html> <head> <title>QGen</title> <meta charset="UTF-8"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script> <style> #modifiedText { white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ } </style> <script> $(document).ready(function() { $('#copyButton').click(function() { var modifiedText = $('#modifiedText').text(); // Create an invisible textarea element to include the modified text var textarea = $('<textarea></textarea>'); textarea.val(modifiedText); $('body').append(textarea); // Copy the text from the textarea element textarea.select(); document.execCommand("copy"); // Remove the textarea element textarea.remove(); // Show confirmation message alert("The modified text has been copied to your clipboard!"); }); }); </script> </head> <body> <h1>QGen</h1> <hr> <div> <p>A simple, no-frills quote generator that puts "> " before each line of a text.</p> </div> <form method="POST"> <textarea name="text" rows="10" cols="50"></textarea><br><br> <input type="submit" name="submit" value="Create quote"> </form> <?php /** * QGen * * Author: Helmut Kaczmarek <email@helmutkaczmarek.de> * Link: https://wiki.helmutkaczmarek.de/code:php:qgen */ if(isset($_POST['submit'])) { // Retrieve text from clipboard $text = $_POST['text']; // Expand each line with "> " at the beginning $lines = explode("\n", $text); $modifiedText = ''; foreach($lines as $line) { $modifiedText .= "> " . $line . "\n"; } // Show the modified text echo "<h2>Modified text:</h2>"; echo "<div>"; echo "<p><pre id='modifiedText'>" . $modifiedText . "</pre></p>"; echo "<p><button id='copyButton'>Copy text</button></p>"; echo "</div>"; } ?> <hr> <div> <p>View <a href="https://wiki.helmutkaczmarek.de/code:php:qgen">sorce code</a>.</p> </div> </body> </html>
code/php/qgen.txt · Zuletzt geändert: 2023-08-19 08:43 von Helmut Kaczmarek