Well, for example: We have an input form:

<input type='text' name='text_user'> 

And the user entered such a message:

ΠŸΡ€ΠΈΠ²Π΅Ρ‚ΠΈΠΊ всСм :)

How to draw a smiley :) and replace it with a picture, for example such -> <img src='Smile_1.jpg'>

    3 answers 3

    There are a lot of solutions.

    You can just do

     <? $string = "ΠŸΡ€ΠΈΠ²Π΅Ρ‚ΠΈΠΊ всСм :)"; $pattern = ":)"; // Ρ‚ΡƒΡ‚ массив со смайлами Π² Π²ΠΈΠ΄Π΅ тСкста для Π·Π°ΠΌΠ΅Π½Ρ‹ $replacement = "<img src='Smile_1.jpg'>"; // Ρ‚ΡƒΡ‚ массив со смайлами Π² Π²ΠΈΠ΄Π΅ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΎΠΊ echo str_replace($pattern, $replacement, $string); ?> 

    Write a little code and voila!

      Google on the topic of implementation of bb code or on the topic of parsing. One of the examples with the description can be found here .

        you can do it right away, javascriptom

         <input id='text_user' type='text' name='text_user' onblur="set_smiles(this.id, this.value)"/> function set_smiles(id, value) { value = value.replace(':)','<img src="Smile_1.jpg">'); document.getElementById(id).value = value; }