473,385 Members | 1,342 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,385 software developers and data experts.

How to echo 4 word from a sentence

123 100+
I want to echo only 4 word from the sentence i selected from the database example (i am the only at home) if i select it from my database and i echo it i want (i am the only)
to display.
Jun 23 '10 #1

✓ answered by zorgi

@simon2x1
What do you need this for?
From your explanation of the problem I would say that solution is:

Expand|Select|Wrap|Line Numbers
  1. $word = "the man is on the way to is house";
  2. echo implode(" ", array_slice(explode(" ", $word), 0, 4));
  3.  
array array_slice ( array $array , int $offset [, int $length [, bool $preserve_keys = false ]] )

string implode ( string $glue , array $pieces )

array explode ( string $delimiter , string $string [, int $limit ] )

3 1399
johny10151981
1,059 1GB
try to understand explode function
Jun 24 '10 #2
simon2x1
123 100+
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $word = "the man is on the way to is house";
  3.  
  4. echo "the man is on the way to is house";
  5.  
  6. //the result is these below
  7. //the man is on the way to is house
  8. ?>
  9.  
if i echo the string $word it will display this "the man is on the way to is house" i just want "the man is on" to display alone how can i do these
Jul 13 '10 #3
zorgi
431 Expert 256MB
@simon2x1
What do you need this for?
From your explanation of the problem I would say that solution is:

Expand|Select|Wrap|Line Numbers
  1. $word = "the man is on the way to is house";
  2. echo implode(" ", array_slice(explode(" ", $word), 0, 4));
  3.  
array array_slice ( array $array , int $offset [, int $length [, bool $preserve_keys = false ]] )

string implode ( string $glue , array $pieces )

array explode ( string $delimiter , string $string [, int $limit ] )
Jul 13 '10 #4

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

Similar topics

2
by: Anouar | last post by:
The point was to make a program that gives you the possibilty to enter a sentence and when you press "enter" it should ask a number for example when i press 4 It should take the 4th word out of...
1
by: smith flyers | last post by:
i got the following error when compiling the codes.. the name 'word' does not exist in the class or namespace 'SimpleMath.Pig' Can anyone troubleshoot on this . Thank you ...
3
by: Oliver Saunders | last post by:
I was really shocked not to find this already submitted by someone in the PHP manual notes. <? function jnWordCount($text) { $results = array(); $pattern = '/+\S+/'; // matches wordy...
10
by: ahoway | last post by:
I am having problems entering a sentence for translating into pig latin. It is set up now to read the entire sentence as one word. I would like to know how to look at each word in the sentence so...
10
by: M | last post by:
Hi, Suppose you have the situation where you have say 20 blocks of text (~250 chars each) in a MySQL db that you need to display, but each has a condition to check to see whether you should...
1
by: iElf | last post by:
can someone point out my error? cus this is printing out garbage and not the longest word... Program ( I underlined the loop Im trying to make to read and find the longest word) everything else...
2
by: valechale | last post by:
I need some serious help!! I am supposed to convert an english sentence to pig latin.... This is what I have so far but everytime I go to compile it it says that word is undeclared!! can someone...
12
by: Archanak | last post by:
Hi, I have a word like this: "Rna binding proteins" and i want to match this exact phrase. I have written code like this: $sentence="Overall, the participation of additional RNA binding...
3
by: houghi | last post by:
I have a parameter $name that contavins e.g. "Turn left at Blooming Grove Turnpike/Quassaic Turnpike/RT-94 Continue to follow RT-94". I just want to have the last word. The number of words will be...
2
by: whodgson | last post by:
The following code accepts a string from the user and swaps the first and last letters in each word. It prints out the original string incorrectly by dropping off the first letter of the first word....
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
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.