943,724 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 515
  • PHP RSS
Nov 7th, 2008
0

What is solution to this query

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
radhigoud is offline Offline
2 posts
since Nov 2008
Nov 7th, 2008
0

Re: What is solution to this query

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?
Reputation Points: 20
Solved Threads: 13
Junior Poster in Training
humbug is offline Offline
93 posts
since Oct 2005
Nov 7th, 2008
0

Re: What is solution to this query

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 :-)
Reputation Points: 52
Solved Threads: 23
Posting Whiz in Training
martin5211 is offline Offline
271 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: mysql_num_rows
Next Thread in PHP Forum Timeline: help in sending php array to mysql table





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC