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
173 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…

685 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