top of page

PHP program to find the last non-repeating character in a String.

  • Nov 2, 2017
  • 1 min read

Source code:

<?php

function find_non_repeat($word) {

$n = strlen($word);

for ($i = $n-1; $i >= 0; $i--) { if (substr_count($word, substr($word, $i, 1)) == 1) { return substr($word, $i, 1); } } }

echo "The last non-repeating character in word 'Programming' is: ".strtoupper(find_non_repeat("Programming")); echo "<br><br>"."The last non-repeating character in 'Daffodil' is: ".strtoupper(find_non_repeat("Daffodil"));

?>

How to run ?

1. Install wampserver / Xamppserver.

2. copy the program and paste in a notepad file.

3. Save the program with .php extension into

C:\xampp\htdocs (or another drive where xampp is installed)

C:\wamp64\www(or another drive where wampserver is installed)

4. Run the server & Open browser and type:

localhost/urfilename.php

Output:

 
 
 

Comments


India

  • Facebook
  • Twitter
  • Instagram

©2017 by Prog Mania. Proudly created with Wix.com

bottom of page