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
169 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
Comment Utility
0
 
LVL 5

Accepted Solution

by:
cammj earned 380 total points
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
The viewer will learn how to count occurrences of each item in an array.

762 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

6 Experts available now in Live!

Get 1:1 Help Now