test php curl - 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 test php curl.php

  1. <?php
  2. // example code
  3.  
  4. function transformUrl($url) {
  5.     // Ensure scheme is present and lowercase
  6.     $url = strtolower($url);
  7.     // Check if the URL starts with "http://" and convert to "https://"
  8.     if (preg_match("~^http://~", $url)) {
  9.         $url = preg_replace("~^http://~", "https://", $url);
  10.     } elseif (!preg_match("~^https://~", $url)) {
  11.         // If the URL doesn't start with "https://", prepend "https://"
  12.         $url = "https://" . $url;
  13.     }
  14.     
  15.     // Parse the URL and decode percent-encoded values
  16.     $parsedUrl = parse_url($url);
  17.     $path = isset($parsedUrl['path']) ? urldecode($parsedUrl['path']) : '';
  18.     
  19.     // Construct the transformed URL without query parameters
  20.     $host = $parsedUrl['host'];
  21.     $transformedUrl = $parsedUrl['scheme'] . '://' . $host . $path;
  22.     
  23.     return $transformedUrl;
  24. }
  25.  
  26.  
  27. echo transformUrl('http://www.homepro.co.th/c/app160301?.a=222'); 
  28. echo "<br>";
  29. echo transformUrl('http://www.homepro.co.th/c/app160301?a=222&b=2333');
  30. echo "<br>";
  31. echo transformUrl('http://www.homepro.co.th/c/app160301');
  32. echo "<br>";
  33. echo transformUrl('http://homepro.co.th/c/app160301?a=222'); 
  34. echo "<br>";
  35. echo transformUrl('http://homepro.co.th/c/app160301?a=222&b=2333');
  36. echo "<br>";
  37. echo transformUrl('http://homepro.co.th/c/app160301');
  38. echo "<br>";
  39. echo transformUrl('homepro.co.th/c/app160301?a=222'); 
  40. echo "<br>";
  41. echo transformUrl('homepro.co.th/c/app160301?a=222&b=2333');
  42. echo "<br>";
  43. echo transformUrl('homepro.co.th/c/app160301');
  44. echo "<br>";
  45. echo transformUrl('www.homepro.co.th/c/app160301?a=222'); 
  46. echo "<br>";
  47. echo transformUrl('www.homepro.co.th/c/app160301?a=222&b=2333');
  48. echo "<br>";
  49. echo transformUrl('www.homepro.co.th/c/app160301');
  50. echo "<br>";
  51. echo transformUrl('http://www.Homepro.co.th/c/app160301?a=222'); 
  52. echo "<br>";
  53. echo transformUrl('http://www.hOmepro.co.th/c/app160301?a=222&b=2333');
  54. echo "<br>";
  55. echo transformUrl('http://www.homepro.co.th/c/app160301');
  56. echo "<br>";
  57. echo transformUrl('https://www.homepro.co.th/c/app160301?.a=222'); 
  58. echo "<br>";
  59. echo transformUrl('https://www.homepro.co.th/c/app160301?a=222&b=2333');
  60. echo "<br>";
  61. echo transformUrl('https://www.homepro.co.th/c/app160301');
  62. echo "<br>";
  63. echo transformUrl('https://homepro.co.th/c/app160301?a=222'); 
  64. echo "<br>";
  65. echo transformUrl('https://homepro.co.th/c/app160301?a=222&b=2333');
  66. echo "<br>";
  67. echo transformUrl('https://homepro.co.th/c/app160301');
File Description
  • test php curl
  • PHP Code
  • 10 Apr-2024
  • 2.35 Kb
You can Share it: