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
170 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses how to create an extensible mechanism for linked drop downs.
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now