Solved

i want a command or a script that i give it a sentince and it finds if there is a word that avilible in the sentence twice and if yes it delets it

Posted on 2008-10-02
3
175 Views
Last Modified: 2008-10-03
i want a command or a script that i give it a sentince and it finds if there is a word that available in the sentence twice and if yes it deletes one of the words.
for example
$sentince = "lol i am on lol fire help me "
after the command or the script i get
$sentence = "lol i am on fire help me"
0
Comment
Question by:mgtm3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Assisted Solution

by:libin_v
libin_v earned 120 total points
ID: 22631687
0
 
LVL 5

Accepted Solution

by:
cammj earned 380 total points
ID: 22631714
Not sure if theres a better way of doing this but

$string = "bob sam cat bob"; // the input text
$temp = explode(" ", $string); // create an array with every word
$temp2 = array_unique($temp); // remove duplicates from the array
$string2=implode(" ", $temp2); // form the array back in to a string

$string2 wouldnt have any duplicates
0
 
LVL 5

Expert Comment

by:cammj
ID: 22631721
A function for what I just mentioned

function foo($strText) {
$temp = explode(" ", $strText); // create an array with every word
$temp2 = array_unique($temp); // remove duplicates from the array
return implode(" ", $temp2); // form the array back in to a string
}
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question