954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

What is solution to this query

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

radhigoud
Newbie Poster
2 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

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?

humbug
Junior Poster in Training
93 posts since Oct 2005
Reputation Points: 20
Solved Threads: 13
 

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 :-)

martin5211
Posting Whiz in Training
271 posts since Aug 2007
Reputation Points: 52
Solved Threads: 23
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You