Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Problem 3. Find All Matches
- //Write a script that finds how many times a substring is contained in a given text (perform case insensitive search).
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- </head>
- <body>
- <form method="post" action="FindAllMatches.php">
- <input type="text" name="str1">
- <input type="text" name="str2">
- <input type="submit" value="GO">
- </form>
- </body>
- </html>
- <?php
- $string=(string)$_POST['str1'];
- $substring=(string)$_POST['str2'];
- $occurrences=substr_count($string, $substring); // 2
- echo "The substring \"$substring\" is countained $occurrences times";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment