What is solution to this query

Reply

Join Date: Nov 2008
Posts: 2
Reputation: radhigoud is an unknown quantity at this point 
Solved Threads: 0
radhigoud radhigoud is offline Offline
Newbie Poster

What is solution to this query

 
0
  #1
Nov 7th, 2008
Hi friends

This is Radhika

Here is the Query:


$str=strlen("Welcome to Program of PHP");
this is o/p:25
But my query is
it should read how many words we like
for example:uptill "welcome":
output is :7....... remaining part should be printed like dots etc.
But use single function only.


advance thanks
Radhika
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 93
Reputation: humbug is an unknown quantity at this point 
Solved Threads: 13
humbug's Avatar
humbug humbug is offline Offline
Junior Poster in Training

Re: What is solution to this query

 
0
  #2
Nov 7th, 2008
What exactly are you asking for? What is a word "we like"? It will probably be possible to write a function to do what you want but I'm not entirely sure what that is.

All in all, what info do you want to get out of the function and what info do you need to put in?
"If your not having fun, your doing something wrong." - Humbug
★ Did I help you out? Did I piss you off? Add to my reputation!
The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 189
Reputation: martin5211 is an unknown quantity at this point 
Solved Threads: 14
martin5211 martin5211 is offline Offline
Junior Poster

Re: What is solution to this query

 
0
  #3
Nov 7th, 2008
Radhika, the problem can be resolved very easy step by step, would be necessary first to make an explode(), separating words using a space delimiter. The result will be an array with each index followed by a word.
Now, inside the function, the for loop will iterate the passed argument (desired words quantity). On each iteration, concatenate a variable passing each array element using as key the variable used into the for loop. Note: Add a space if it's necessary too between each concatenation. Also, due to the array start with zero value, the first passed argument should be decreased once.
After the loop, you will have a variable only with some words passed, you can finally apply strlen() to count the elements.

Good luck :-)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC