gdfghd - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of gdfghd.php

  1. <?php
  2. $email = "john_smith@hotmail.com"; // Or Use $_GET['subject']; / $_POST['subject']; depending on form
  3. $parts = explode("@",$email); // Splits the email at the @ symbol
  4. $username = $parts[0]; // Can be used as a username if you'd like, but we'll use it to find names anyway
  5.  
  6. $delimiters = array(".", "-", "_"); // List of common email name delimiters, feel free to add to it
  7.  
  8. foreach ($delimiters as $delimiter){ // Checks all the delimiters
  9.         if ( strpos($username, $delimiter) ){ // If the delimiter is found in the string
  10.           $parts_name = preg_replace("/\d+$/","", $username); // Remove numbers from string
  11.           $parts_name = explode( $delimiter, $parts_name); // Split the username at the delimiter
  12.           break; // If we've found a delimiter we can move on
  13.         }
  14. }
  15.  
  16. if ( $parts_name ){ // If we've found a delimiter we can use it
  17. $fname = ucfirst( strtolower( $parts_name[0] ) ); // Lets tidy up the names so the first letter is a capital and rest lower case
  18. $lname = ucfirst( strtolower( $parts_name[1] ) );
  19.  
  20. /* This code just shows what you can do with the names, but you can use it for something more interesting! */
  21. echo $fname . ' ' . $lname;
  22. }
File Description
  • gdfghd
  • PHP Code
  • 03 Dec-2023
  • 1.14 Kb
You can Share it: