PHP - Simple String Conversion

Submitted by: 
Language: 
Visitors have accessed this post 303 times.

In this tutorial we will create a Simple String Conversion using PHP. This code can be use in converting some string easily and automated. PHP is a server-side scripting language designed primarily for web development. Using PHP, you can let your user directly interact with the script and easily to learned its syntax. It is mostly used by a newly coders for its user friendly environment. So Let's do the coding.

Getting started

First you have to download & install XAMPP or any local server that run PHP scripts. In my case I used XAMPP as my local server, here's the link for XAMPP server https://www.apachefriends.org/index.html.

The Main Function

This code contains the main function of the application, This code will automatically convert your string to lowercase or uppercase depend on the word itsetl.To create this just write these block of code in the text editor, then name this file as convert.php

  1. <?php
  2. if(ISSET($_GET['word']) && !empty($_GET['word'])){
  3. if(ctype_lower($_GET['word'])){
  4. $word=$_GET['word'];
  5. $upper_word=strtoupper($word);
  6. echo "<h2 class='text-danger'>".$upper_word."</h2>";
  7. }else if(ctype_upper($_GET['word'])){
  8. $word=$_GET['word'];
  9. $lower_word=strtolower($word);
  10. echo "<h2 class='text-danger'>".$lower_word."</h2>";
  11. }
  12. }
  13. ?>

The Main Interface

This is the interface that display the output of the conversion,to make this just write these codes inside your text file, Then save it as index.php

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1"/>
  5. <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
  6. </head>
  7. <body>
  8. <nav class="navbar navbar-default">
  9. <div class=container-fluid>
  10. <a class="navbar-brand" href="<a href="https://sourcecodster.com">Sourcecodester</a>
  11. " rel="nofollow">https://sourcecodster.com">Sourcecodester</a>
  12. </a> </div>
  13. </nav>
  14. <div class="col-md-3"></div>
  15. <div class="col-md-6 well">
  16. <h3 class="text-primary">PHP - Simple String Conversion</h3>
  17. <hr style="border-top:1px dotted #000;"/>
  18. <form method="GET" action="">
  19. <div class="col-md-3"></div>
  20. <div class="form-inline col-md-8">
  21. <h3>Type a Word</h3>
  22. <label class="text-success">*Word must be all UPPER or lower to make this work</label>
  23. <br /><br />
  24. <input type="text" name="word" class="form-control"/>
  25. <button type="submit" class="btn btn-primary">Convert</button>
  26. <br /><br />
  27. <?php include'convert.php'?>
  28. </div>
  29. </form>
  30. </div>
  31. </body>
  32. </html>

There you have it we successfully created a Simple String Conversion using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.