0

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

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by martin5211
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?

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.