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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mysqli_query() expects parameter 1 to be msqli, string given in 4 64
Creating Functions in phpMyAdmin 8 26
Undefined variable problem 5 23
JQuery Search Filter 2 32
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

837 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