473,378 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

complex loops

hi my goal is to create a form that grabs all the words and deletes a letter from every combination....

for example....

if i submited - Jordan William

i would want my return result to echo...

jordan jorda jordn joran jodan jrdan ordan

william willim willam wiliam wiliam wlliam illiam

this is only how far i can get ive tryed alot of mixed loops but cant get it to work and now im totally stuck...

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. $words = eregi_replace(" +", " ",$words);  
  4.  
  5. $indivualWords = explode(' ', $words);
  6.  
  7.  
  8.  
  9.  
  10.                for($i=0; $i < count($indivualWords); $i++){
  11.  
  12.  
  13.  
  14.                   $indivualWords[$i] = substr_replace($indivualWords[$i],"",-1);
  15.  
  16.  
  17.                   echo  $indivualWords[$i] . "<br />" ;   
  18.               }  
  19.  
  20.   }  
  21.  
  22.  
  23.  
Oct 11 '10 #1
4 1349
even if i changed the -1 to $x-- using another for loop
some how i need to repeat only $x-- untill the strlen of the word is done then repeat the $i++ when the first word is done, then do the same for the next word and so on, im so confused.
Oct 11 '10 #2
this works but need ta transfer it from hard code into loops as it would need to be flexable depending on how many words in the form and how many letters the word has... any help would be appreciated :)

this is the code

Expand|Select|Wrap|Line Numbers
  1.  $words = eregi_replace(" +", " ", $words);  
  2.  
  3.     $indivualWords = explode(' ', $words);
  4.  
  5.  
  6.  
  7.  
  8.                for($i=0; $i < count($indivualWords); $i++){
  9.  
  10.  
  11.  
  12.                   $indivualWords1[$i] = substr_replace($indivualWords[$i],"",-1,1);
  13.  
  14.                   $indivualWords2[$i] = substr_replace($indivualWords[$i],"",-2,1); 
  15.  
  16.                   $indivualWords3[$i] = substr_replace($indivualWords[$i],"",-3,1); 
  17.  
  18.                   $indivualWords4[$i] = substr_replace($indivualWords[$i],"",-4,1); 
  19.  
  20.                   $indivualWords5[$i] = substr_replace($indivualWords[$i],"",-5,1); 
  21.  
  22.  
  23.                   echo  $indivualWords1[$i] . "<br />" ;  
  24.                   echo  $indivualWords2[$i] . "<br />" ; 
  25.                   echo  $indivualWords3[$i] . "<br />" ; 
  26.                   echo  $indivualWords4[$i] . "<br />" ; 
  27.                   echo  $indivualWords5[$i] . "<br />" ; 
  28.  
  29.  
  30.               }  
  31.  
  32.   }  
  33.  
  34.  
  35.  
  36.  
  37. }
  38.  
Oct 11 '10 #3
dlite922
1,584 Expert 1GB
You're almost there!!

Inside your for loop get the length of $individualWord and create another for loop that traverses this many times. This will allow you to do different-length words.

Inside this inner for loop, do the letter removal and store each of these combination in a new array.

I'm curious why you're doing this or what you're doing this for? You do know there are functions that can find similar words based on sound (pronunciations) or closeness in spelling (order of letters), for example soundex().

Cheers and Good Luck,

Dan
Oct 11 '10 #4
thankyou for your help, im am still a bit stuck but got a little further, this is my code now, it works but only for the first word in the form, and does way to many combinations,

Expand|Select|Wrap|Line Numbers
  1.  
  2.  $words = eregi_replace(" +", " ", $words);  
  3.  
  4.     $indivualWords = explode(' ', $words);
  5.  
  6.  
  7.  
  8.  
  9.             for($i=0; $i < count($indivualWords); $i++){ 
  10.  
  11.  
  12.                 $length = strlen($indivualWords[$i]);
  13.  
  14.  
  15.                   for($y=$length; $y > -1; $y--){
  16.  
  17.  
  18.                   $indivualWords[$y] = substr_replace($indivualWords[$i],"",$y,1); 
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.                   echo  $indivualWords[$y] . "<br />" ;  
  26.  
  27.                 }
  28.               }   
  29.   }
  30.  
  31. }
  32.  
  33.  
if i type william jordan in the form and click submit it echo's .....

william
willia
willim
willam
wiliam
wiliam
wlliam
illiam
wlliam
wllia
wllim
wllam
wliam
wliam
liam
wliam
wlia
wlim
wlam
wam
lam
wlim
wli
wl
wi
li
wlim
wli
wlm
wim
lim
wliam
wlia
wlim
wlam
wiam
liam
wlliam
wllia
wllim
wllam
wliam
wliam
lliam
william
willia
willim
willam
wiliam
wiliam
wlliam
illiam

im happy and its correct but i only want the first 8...

william
willia
willim
willam
wiliam
wiliam
wlliam
illiam

and also need to edit my script so it looks for the all words on the form.

i was hoping to learn a lot from this experiment, im hoping that im nearly there but think im going over my head with this :(
Oct 11 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dan | last post by:
Hello, I am trying to read and write to an Excel file via my Java applet. I have done so successfully on several simple Excel files that simply had data cells without many complicated equations...
5
by: Tank | last post by:
I have had this post up here when i was trying to figure out how to make leading zeros and have been able to fudge that to work. I am now have trouble getting the loop that makes the folders to...
1
by: David Goodyear | last post by:
At the moment im experimenting with ideas in C++ and would really like to solve the following, please please help. Sorry i dont even know what the subject is this would come under? :( Sorry if...
3
by: dd_bdlm | last post by:
Please help this one is driving me mad! I have searched and read all the topics on the error message I am receiving but none seem to apply to me! I have quite a complex query linking all parts...
7
by: Tigger | last post by:
Dear Experts, I am working on ASP.NET. I have got a problem related to the usage of Javascript in ASP.NET. Please help. The story is the following: 1) I am developing an ASP.NET application. I...
0
by: kbloom503 | last post by:
Hi. I am required to take a VB .net 2005 programming course for my business major so have no clue what I am doing. I have a final homework assignment that needs to include a command control that will...
22
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of...
6
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID,...
1
by: pstuning | last post by:
if you see the cost of QUERY time in below joining of table and 2 views we can easily say it is taking a lot of time. This is a production support issue and i need some help. SELECT...
1
by: tangengot456 | last post by:
sir, maam, i am very confused with my assignment regarding how to do a multiplication table using arrays and loops in C.. please help me. i would gladly appreciate whatever help you...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.