SubStr() - 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 SubStr().php

  1. <?php
  2.  
  3. function countSub($string, $sub){
  4.     $c = 0;
  5.     for($i=0;$i < strlen($string); $i++){
  6.         if(strpos(substr($string,$i,strlen($string)-1-$i), $sub) != false){
  7.             $c++;
  8.         }
  9.     }
  10.     
  11.     return $c;
  12. }
  13. echo countSub("ma ma","ma");
  14.  
  15. ?>
  16.  
File Description
  • SubStr()
  • PHP Code
  • 26 Sep-2022
  • 260 Bytes
You can Share it: