Delete Repeated Words from Variable

Asked

Viewed 118 times

-3

Follows the code:

$selbanco = "SELECT * FROM exemplo WHERE id=5";
$querybanco = mysql_query($selbanco);


while($teste=mysql_fetch_array($querybanco)){

  $testando = $teste['teste'];
}

<td id="idcampo"> ><?php 
  if($teste1>$teste2){
      echo "$testando";
      } 
          else {
echo "(Agurde)" </td>


<script>var exemplo = $("#idcampo").html();</script>
$exemplo = "<script>document.write(exemplo)</script>";

echo $exemplo;

When displaying this example variable with echo it returns "example example" , it would have some command or something you can use to return only "example" without repeating the word?

Note: The variable taken in the database is duplicated ("example example")

  • show me where is the answer to my question ?

  • Exactly in your previous question. The fact that you don’t understand doesn’t make it not duplicate. Just use the answer code you yourself accepted, and apply before the echo. I would suggest you elaborate your questions better, here everyone wants to help, but if you do not explain it well, it is difficult. I hope you understand that to get an answer that solves your problem, it is critical that you can explain it properly.

  • The answer does not work for this question as I capture the variable in a different way, the code given in the previous question DOES NOT ANSWER THIS QUESTION.

  • 1

    It serves, but you’re getting lost when mixing PHP with JS.

  • so I’m asking for help, if I didn’t need help I wasn’t here

  • implemented the code and it continues to duplicate the variable, IT DOES NOT SERVE.

  • 1

    So then you have to help us and put the problem exactly as it really is. If you keep throwing questions in half, the whole community is wasting their time with things that don’t fit. And like I said, if you don’t know the first thing about what you’re doing, it’s not the community’s fault. Anyway, if anyone understands you’re not a duplicate, just vote to reopen. It is suggested that you create a [mcve], and then we can help on top of it.

  • So I created this question, to explain the problem correctly, because I had already accepted the answer in the other and after accepting it n would change the question.

  • 1

    And did you accept it without serving? Notice that you are misusing community resources. Like I said, if you try to use it more carefully, it’ll be better for you and for us. What I’m trying to tell you is to help you too. Just what you put here in the question, the problem remains the same. If it doesn’t fit, click the [Edit] on this one, and explain your problem with a functional example of the problem.

  • I accepted because the code was correct, and when tested separately it worked, but when incrementing to the rest of the n code it worked more

  • Then edit this one with all your code and the one that makes it easier for us to help.

  • reopen please seeing that the previous answer n serves for this question n there is a duplicate question here

  • 1

    You have to make it not duplicate. The way it is, the problem is the same. You can [Dit] at any time adding what you tried to do, then it is easier to find the error. Put the code already with the part that gives problem and what used the other and did not work. Then we will probably find the error more easily.

  • You’ve improved a bit, but you missed the part of the other answer, no?

  • 1

    Look, I voted to reopen so as not to cause any more trouble, but try to understand what I said, which makes it easier for you and us. The way it is, I still don’t think it can be solved, so see what you can do to make it easier for those who are helping to understand the real problem. See this as a way for you to help those who help you with answers.

  • I got the code if I can find the problem now I’d appreciate it

Show 11 more comments

1 answer

1

Would you have some 'command' or something you can use to return just "example" without repeating the word?

The answer to is question is yes, but for the question in general there is no way to answer because this question was not very well 'architected'.

implode(' ',array_unique(explode(' ', 'exemplo exemplo')));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.