test - 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.
Result of php executing
Full code of test.php
- <?php
- function isSubstringInInfiniteString($infStr, $toFind) {
- $len_infStr = strlen($infStr);
- $len_toFind = strlen($toFind);
- // Check if the second string is longer than the first string
- if ($len_toFind > $len_infStr) {
- return "NO";
- }
- // Create a substring of the first string with the length of the second string
- $substr = substr($infStr, 0, $len_toFind);
- // Check if the second string appears as a substring when the first string is repeated infinitely
- if (strpos(str_repeat($infStr, ceil($len_toFind / $len_infStr) + 1), $toFind) !== false) {
- return "YES";
- } else {
- return "NO";
- }
- }
- // Read the number of test cases
- $T = intval(trim(fgets(STDIN)));
- // Iterate through each test case
- for ($i = 0; $i < $T; $i++) {
- // Read the parameters for the current test case
- list($infStr, $toFind) = explode(" ", trim(fgets(STDIN)));
- // Output whether the second string is a substring of the infinite string
- echo isSubstringInInfiniteString($infStr, $toFind) . "\n";
- }
- ?>